1

I am trying to get orders for a specific customer through API:

GET on https://domain.com/index.php/rest/V1/orders

and header parameter is

Authorization Bearer x1v9pvmag5rvkb0vgekpdtwri6ak1pxh

but also get error

{"message":"Consumer is not authorized to access %resources","parameters":{"resources":"Magento_Sales::sales"}}

Please help.

asked Mar 19, 2017 at 12:12
6
  • Can you post your GET data? Commented Mar 19, 2017 at 12:35
  • I didn't get any data except the error Commented Mar 19, 2017 at 12:46
  • I mean the passed data to this api? Commented Mar 19, 2017 at 12:48
  • I didn't pass any data. only the header authorization parameter. Commented Mar 19, 2017 at 12:51
  • What about posting your permissions for the role associated with that bearer? Commented Mar 19, 2017 at 15:17

1 Answer 1

1

If you have curl installed, you can use the following command to get a token. Replace the following:

  • BASE_URL is your magento 2 domain, like https://domain.com
  • ADMIN_NAME is the username that you use to login to the admin backend
  • ADMIN_PASSWORD is the password that you to login to the admin backend

curl -X POST "BASE_URL/index.php/rest/V1/integration/admin/token" -H "Content-Type:application/json" -d '{"username": "ADMIN_NAME", "password": "ADMIN_PASSWORD"}'

It will return a token. Copy that token and try your get again. To do it with curl, you can try the following. I added searchCriteria to only get the first 10 records. You have to escape [] with \ in curl. Also, make sure you replace BASE_URL and TOKEN:

curl -X GET "BASE_URL/index.php/rest/V1/orders/?searchCriteria\[currentPage\]=1&searchCriteria\[pageSize\]=10" -H "Content-Type:application/json" -H "Authorization: Bearer TOKEN"

answered Mar 20, 2017 at 18:39
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.