Magento2 REST API – Fix Consumer Not Authorized to Access Resources

magento2

I created a new customer and got the token perfectly but when I try to access any API like

http://myhost.com/index.php/rest/V1/customers/me?Authorization=Bearerhy23vc01x9s1jd2t8gho47g58trllc0b 

got the error

<?xml version="1.0"?>
<response>
<message>Consumer is not authorized to access %resources</message>
<parameters>
<resources>self</resources>
</parameters>
  <trace>#0 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/RequestValidator.php(70): Magento\Webapi\Controller\Rest\RequestValidator-&gt;checkPermissions()
#1 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/InputParamsResolver.php(80): Magento\Webapi\Controller\Rest\RequestValidator-&gt;validate()
#2 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(299): Magento\Webapi\Controller\Rest\InputParamsResolver-&gt;resolve()
#3 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest-&gt;processApiRequest()
#4 /var/www/myhost.com/public_html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#5 /var/www/myhost.com/public_html/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#6 /var/www/myhost.com/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http-&gt;launch()
#7 /var/www/myhost.com/public_html/index.php(39): Magento\Framework\App\Bootstrap-&gt;run(Object(Magento\Framework\App\Http))
#8 {main}</trace>
</response>

please any help

Best Answer

The Authorization token is NOT place on the parameter. Should be set on header instead. Here is an example on POSTMAN:

enter image description here

On cURL, it will be:

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer XXXXXXXXXX" "http://yoursite.com/rest/V1/products/:sku"