cancel
Showing results for 
Search instead for 
Did you mean: 

Array ( [message] => Consumer is not authorized to access %resources [parameters] => Array ( [resour

Array ( [message] => Consumer is not authorized to access %resources [parameters] => Array ( [resour

I have a magento2.0 installed. I am fetching products and orders from that.

I have fetch products from every type of access token(admin, customer, integration). But not getting Orders from any one of them.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://magento-host/index.php/rest/V1/integration/customer/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"username":"logita.consatcloud@gmail.com", "password":"Main1029!"}');
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo "<pre>";
print_r(json_decode($result,true));
$res=json_decode($result,true);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://magento-host/rest/V1/orders");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Bearer ".$res;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo "<pre>";
print_r(json_decode($result,true));

 

I tried the same with admin/token with admin Url.

I was recommended to reindex the magento. I followed that that run code for reindex.But didnt find anything. 

Thankyou in advance.