Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 API always returns Consumer is not authorized to access %resources

I am trying to use the Magento 2 rest API, but even when just curl'ing from command line, the only response I get is Consumer is not authorized to access %resources

I managed to get a token with

curl -X POST "http://magento.dev.blackorange.nl/index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"adminuser", "password":"adminpass"}'`

but when i try

curl -X GET -H "Authorization: Bearer TOKEN" "http://magento.dev.blackorange.nl/rest/V1/products" 

(or any other endpoint) I get the-the Consumer is not authorized to access %resources message

Am I missing a step somewhere?

like image 638
Werring Avatar asked Oct 19 '22 07:10

Werring


2 Answers

make sure you are using Magento2 admin username password not any API Username Password With proper roles are assigned to that user , if this does not work try changing the ROLE : ALL

to access GET /V1/products you need to pass searchCriteria parameter its required parameter.

1st you need to call admin/token API the token you get from here you need to pass in 2nd API

replace TOKEN with your token Key from 1st Call

curl -X GET -H "Authorization: Bearer ntfw****avefg***6mil***kysnl3***" "http://magento.dev.blackorange.nl/rest/V1/products" 

for all REST API Reference : http://devdocs.magento.com/swagger/index.html#/

like image 119
Emizen Tech Avatar answered Oct 27 '22 17:10

Emizen Tech


Try it with trimming the token value. It gets blank space which makes it incorrect.

like image 26
Aman Srivastava Avatar answered Oct 27 '22 17:10

Aman Srivastava