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 Truong– Khoa Truong2017年03月19日 12:35:17 +00:00Commented Mar 19, 2017 at 12:35
- 
 I didn't get any data except the errorJsparo30– Jsparo302017年03月19日 12:46:18 +00:00Commented Mar 19, 2017 at 12:46
- 
 I mean the passed data to this api?Khoa Truong– Khoa Truong2017年03月19日 12:48:42 +00:00Commented Mar 19, 2017 at 12:48
- 
 I didn't pass any data. only the header authorization parameter.Jsparo30– Jsparo302017年03月19日 12:51:03 +00:00Commented Mar 19, 2017 at 12:51
- 
 What about posting your permissions for the role associated with that bearer?Brett– Brett2017年03月19日 15:17:44 +00:00Commented Mar 19, 2017 at 15:17
1 Answer 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"