I have created a custom admin user and gave access rights to access all the magento modules.
Now when i hit the url to get product info by passing sku in url from postman.
and select authorization type basic auth with username and password which i have created from admin, it gives me error
Consumer is not authorized to access %resources.
how can i fix that or is there any way to access Magento API's using basic auth?
-
First, you need to make call to get Admin Token: Endpoint POST http://<host>/rest/default/V1/integration/admin/token Headers Content-Type application/json Data: { "username": "admin", "password": "123123q" } Response: Magento returns the admin’s access token. 5r8cvmpr11j6gmau8990rcj2qk7unh8i Now, You can call product info API. but in each call use header like below: Authorization: Bearer <authentication token>Pankaj Pareek– Pankaj Pareek2018年07月20日 13:10:31 +00:00Commented Jul 20, 2018 at 13:10
3 Answers 3
Magento support confirmed to me in a ticket that by default it is not possible to use the REST API while HTTP Access Control is enabled.
It would be possible using custom code or a custom VCL file if you're using Fastly/Varnish but those are complex solutions.
These are the steps to properly create an authentication token and use it in an authenticated API REST
First call the authentication API REST to get the token
First call the authentication API REST to get the token
Now paste the token in the Baerer token authorization field and call the API REST
To fix this error you need to pass the access token. Because guest user doesn't have access to it.
Just check following article you will get more idea.
Also, check this answer. I had same issue and someone helped me to fix it:
magento 2 Rest APi How to use default methods
Please let me know if you still need help. I'll help you.