Magento 2 API – Get All Store IDs, Names, and Codes
End-to-end Magento integration
Integrate any app or service. Consult our API development experts.
Hello, Magento peeps!
In my last blog post on Magento 2 API, I provided complete tutorial to get admin token through API. In case you missed it, you can catch it at: Magento 2 API – Get Admin Token. In this blog post, I will show you how you can get all store ids, names, and codes through Magento 2 API.
Being a robust, powerful and customizable eCommerce platform, Magento 2 facilitates the developers to use the platform from anywhere through its APIs. The APIs make can be used to exchange data seamlessly between the applications.
If you are having multiple store-views in your Magento 2 store, and want to display specific store-views, you may require to get all the store IDs, names, and codes. It can be easily done by calling Magento 2 API – Get All Store IDs, Names, and Codes.
Here is the complete tutorial to get all store ids, names, and codes through Magento 2 APIs.
How to Get All Store IDs, Names, and Codes Using Magento 2 API?
In order to get all store IDs, names, and codes in Magento 2 through API, we’ll perform a GET call to /V1/store/storeGroups endpoint. From the v2.4 onwards, Magento restricts the anonymous access to many of the APIs for security purposes and this is one of them. Therefore, we need to pass the authorization token to get all store IDs, names, and codes through Magento 2 API.
Here is the complete Magento 2 API call to get all store IDs, names, and codes.
- Method: GET
- URL: store_url/rest/V1/store/storeGroups
- Authorization Type: Bearer Token
- Token:<admin token>
Response:
On calling the above request, you’ll get all the store IDs, names, and codes in Magento 2 in the following format:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[ { "id": 0, "website_id": 0, "root_category_id": 0, "default_store_id": 0, "name": "Default", "code": "default" }, { "id": 1, "website_id": 1, "root_category_id": 2, "default_store_id": 1, "name": "Main Website Store", "code": "main_website_store" }, { "id": 2, "website_id": 3, "root_category_id": 14, "default_store_id": 2, "name": "new store", "code": "new_store" } ] |
That’s it! This is how you can get all store IDs, names, and codes in Magento 2 through the API.
Conclusion
If you are developing a Magento 2 app, there can be instances when you require to fetch all store IDs to work on a specific store view. You can use perform an API call to Magento 2 by passing the authentication token to get IDs, names, and codes of all the storeviews.
In case you still have any queries or doubts regarding it, feel free to comment. I would be happy to help you. 💫
Also, do not forget to share this Magento 2 API tutorial with your developer friends through social media! 🔗
Thanks for reading. 😊
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
Magento 2 API – Get Admin Token
Solved: “Expecting a string, got NULL”,”1″:…” in Magento 2
Next