Magento – Magento 2 Rest API using basic Auth

magento2rest api

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.

http://local.m2.com/rest/V1/products/24-MB02

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?

Best Answer

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>
Related Topic