Magento 2.x – Rest APIs – Fix The consumer isn’t authorized to access %resources.
If you face the following message when you try to access to the Magento Rest API, it is because you do not have the authorization to access the requested API.
Magento have a couple of ways to get you authorized : https://devdocs.magento.com/guides/v2.3/get-started/authentication/gs-authentication.html
But in this case, we are going to explain in a easy way how to get that solved with the Token Based Authentication.
- First step, is calling http://<your_url>/index.php/rest/V1/integration/admin/token though a POST request. Where you will get the corresponding and needed token.
- Second step, is adding the “Bearer” as authorization in the API call that we were not authorized before, using the pattern “Bearer <token>” as Authorization param.
- Once this is done, you will be able to fill in the corresponding body, and run the API call you need (in this case, its a sales order creation).
That’s it. Happy coding.!