I am new to Magento. Please help me understand how to fetch the products.
I believe there are some changes to be made in .htaccess file present in the root folder for this url: http://localhost/magento2/index.php/rest/V1/products to return the values.
This the response that I am getting :
Consumer is not authorized to access %resources
Magento_Catalog::products
.
Can someone please help me here.
Best Answer
It seems to be a problem with the User Role.
To get started with the REST API in Magento 2 using token-based authentication, you will need to create a web service User Role and register that role to a new Magento 2 Admin User.
Now, create a new user for the newly created role through these steps:
Now, I will pass the newly created username and password with the API URL in the initial connection and receive the token. This token will be saved in a variable, which will be passed in the header for further calls.
You can fetch almost everything using Magento 2 REST API. In this answer, I will be fetching All Modules, but you can check out the List of REST APIs for Magento Open Source and see what you needed.
Now, I will pass the token (fetched earlier) in the header with the API URL to get all the modules installed on Magento 2 store.
Once you execute the above code (with relevant information), run the file in the browser and you will see output similar to the following:
If you need further help, check this complete guide: https://www.cloudways.com/blog/magento-2-rest-api/