Megento 2 stdClass Object ( [message] => Consumer is not authorized to access %resources [parameters]...











up vote
0
down vote

favorite












I have magento2.1 installed in my server under folder magento2. So base Url is
http://$domain/magento2/



After this I have created a new role as admin and under permission clicked All.Then I created a new user with username, password and other details. Then connected the new user to new role.



After that i call the admin/token by passing username and password as



$apiURL="http://".$domain."/magento2/index.php/rest/V1/integration/admin/token";

//parameters passing with URL
$data = array("username" => "username", "password" => "!pass");
$data_string = json_encode($data);

$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string)));
print_r(curl_getinfo($ch));
$token = curl_exec($ch);

//decoding generated token and saving it in a variable
echo $token= json_decode($token,true);


This gave a token but on print the http_code it gives 0. I tried through Postman too.



dadtaqm9b5bjqr6tk35hj8b6iy8a6hou //token


Then i called the customer/me endpoint



$token= trim($token);
//Using above token into header
$headers = array("Authorization: Bearer ".$token,"Accept:application/json");

//API URL to get all Magento 2 modules
$requestUrl='http://'.$domain.'/magento2/index.php/rest/V1/customers/me';

$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//print_r(curl_getinfo($ch));
$result = curl_exec($ch);

//decoding result
$result= json_decode($result);

//printing result
print_r($result);


This gave output as



stdClass Object ( [message] => Consumer is not authorized to access %resources [parameters] => stdClass Object ( [resources] => self ) )


Any solution to this problem?
New role



Role permission



user










share|improve this question


















  • 1




    It may duplicated magento.stackexchange.com/questions/150190/…
    – Jared Chu
    20 hours ago










  • I went through the link. no success.
    – Logita Kurrey
    17 hours ago















up vote
0
down vote

favorite












I have magento2.1 installed in my server under folder magento2. So base Url is
http://$domain/magento2/



After this I have created a new role as admin and under permission clicked All.Then I created a new user with username, password and other details. Then connected the new user to new role.



After that i call the admin/token by passing username and password as



$apiURL="http://".$domain."/magento2/index.php/rest/V1/integration/admin/token";

//parameters passing with URL
$data = array("username" => "username", "password" => "!pass");
$data_string = json_encode($data);

$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string)));
print_r(curl_getinfo($ch));
$token = curl_exec($ch);

//decoding generated token and saving it in a variable
echo $token= json_decode($token,true);


This gave a token but on print the http_code it gives 0. I tried through Postman too.



dadtaqm9b5bjqr6tk35hj8b6iy8a6hou //token


Then i called the customer/me endpoint



$token= trim($token);
//Using above token into header
$headers = array("Authorization: Bearer ".$token,"Accept:application/json");

//API URL to get all Magento 2 modules
$requestUrl='http://'.$domain.'/magento2/index.php/rest/V1/customers/me';

$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//print_r(curl_getinfo($ch));
$result = curl_exec($ch);

//decoding result
$result= json_decode($result);

//printing result
print_r($result);


This gave output as



stdClass Object ( [message] => Consumer is not authorized to access %resources [parameters] => stdClass Object ( [resources] => self ) )


Any solution to this problem?
New role



Role permission



user










share|improve this question


















  • 1




    It may duplicated magento.stackexchange.com/questions/150190/…
    – Jared Chu
    20 hours ago










  • I went through the link. no success.
    – Logita Kurrey
    17 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have magento2.1 installed in my server under folder magento2. So base Url is
http://$domain/magento2/



After this I have created a new role as admin and under permission clicked All.Then I created a new user with username, password and other details. Then connected the new user to new role.



After that i call the admin/token by passing username and password as



$apiURL="http://".$domain."/magento2/index.php/rest/V1/integration/admin/token";

//parameters passing with URL
$data = array("username" => "username", "password" => "!pass");
$data_string = json_encode($data);

$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string)));
print_r(curl_getinfo($ch));
$token = curl_exec($ch);

//decoding generated token and saving it in a variable
echo $token= json_decode($token,true);


This gave a token but on print the http_code it gives 0. I tried through Postman too.



dadtaqm9b5bjqr6tk35hj8b6iy8a6hou //token


Then i called the customer/me endpoint



$token= trim($token);
//Using above token into header
$headers = array("Authorization: Bearer ".$token,"Accept:application/json");

//API URL to get all Magento 2 modules
$requestUrl='http://'.$domain.'/magento2/index.php/rest/V1/customers/me';

$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//print_r(curl_getinfo($ch));
$result = curl_exec($ch);

//decoding result
$result= json_decode($result);

//printing result
print_r($result);


This gave output as



stdClass Object ( [message] => Consumer is not authorized to access %resources [parameters] => stdClass Object ( [resources] => self ) )


Any solution to this problem?
New role



Role permission



user










share|improve this question













I have magento2.1 installed in my server under folder magento2. So base Url is
http://$domain/magento2/



After this I have created a new role as admin and under permission clicked All.Then I created a new user with username, password and other details. Then connected the new user to new role.



After that i call the admin/token by passing username and password as



$apiURL="http://".$domain."/magento2/index.php/rest/V1/integration/admin/token";

//parameters passing with URL
$data = array("username" => "username", "password" => "!pass");
$data_string = json_encode($data);

$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Content-Length: ".strlen($data_string)));
print_r(curl_getinfo($ch));
$token = curl_exec($ch);

//decoding generated token and saving it in a variable
echo $token= json_decode($token,true);


This gave a token but on print the http_code it gives 0. I tried through Postman too.



dadtaqm9b5bjqr6tk35hj8b6iy8a6hou //token


Then i called the customer/me endpoint



$token= trim($token);
//Using above token into header
$headers = array("Authorization: Bearer ".$token,"Accept:application/json");

//API URL to get all Magento 2 modules
$requestUrl='http://'.$domain.'/magento2/index.php/rest/V1/customers/me';

$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//print_r(curl_getinfo($ch));
$result = curl_exec($ch);

//decoding result
$result= json_decode($result);

//printing result
print_r($result);


This gave output as



stdClass Object ( [message] => Consumer is not authorized to access %resources [parameters] => stdClass Object ( [resources] => self ) )


Any solution to this problem?
New role



Role permission



user







magento magento2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 20 hours ago









Logita Kurrey

268




268








  • 1




    It may duplicated magento.stackexchange.com/questions/150190/…
    – Jared Chu
    20 hours ago










  • I went through the link. no success.
    – Logita Kurrey
    17 hours ago














  • 1




    It may duplicated magento.stackexchange.com/questions/150190/…
    – Jared Chu
    20 hours ago










  • I went through the link. no success.
    – Logita Kurrey
    17 hours ago








1




1




It may duplicated magento.stackexchange.com/questions/150190/…
– Jared Chu
20 hours ago




It may duplicated magento.stackexchange.com/questions/150190/…
– Jared Chu
20 hours ago












I went through the link. no success.
– Logita Kurrey
17 hours ago




I went through the link. no success.
– Logita Kurrey
17 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370749%2fmegento-2-stdclass-object-message-consumer-is-not-authorized-to-access-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370749%2fmegento-2-stdclass-object-message-consumer-is-not-authorized-to-access-r%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Saint-Aignan (Tarn-et-Garonne)

Volksrepublik China

How to test boost logger output in unit testing?