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.

  • Can you post your GET data? – Khoa TruongDinh Mar 19 '17 at 12:35
  • I didn't get any data except the error – Jsparo30 Mar 19 '17 at 12:46
  • I mean the passed data to this api? – Khoa TruongDinh Mar 19 '17 at 12:48
  • I didn't pass any data. only the header authorization parameter. – Jsparo30 Mar 19 '17 at 12:51
  • What about posting your permissions for the role associated with that bearer? – Brett Mar 19 '17 at 15:17
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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.