{"id":2540,"date":"2024-12-31T20:22:45","date_gmt":"2024-12-31T20:22:45","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-api-get-all-store-ids-names-and-codes\/"},"modified":"2025-04-24T09:39:46","modified_gmt":"2025-04-24T04:09:46","slug":"magento-2-api-get-all-store-ids-names-codes","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-api-get-all-store-ids-names-codes\/","title":{"rendered":"Magento 2 API &#8211; Get All Store IDs, Names, and Codes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello, Magento peeps!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my last blog post on&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>, I provided complete tutorial to get admin token through API. In case you missed it, you can catch it at:&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-admin-token\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API \u2013 Get Admin Token<\/a>. In this blog post, I will show you how you can get all store ids, names, and codes through Magento 2 API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&nbsp;<em><strong>Magento 2 API \u2013 Get All Store IDs, Names, and Codes<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the complete tutorial to get all store ids, names, and codes through Magento 2 APIs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Get All Store IDs, Names, and Codes Using Magento 2 API?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to get all store IDs, names, and codes in Magento 2 through API, we\u2019ll perform a GET call to&nbsp;<em><strong>\/V1\/store\/storeGroups&nbsp;<\/strong><\/em>endpoint. From the v2.4 onwards, Magento restricts the&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/webapi\/rest\/\" target=\"_blank\" rel=\"noreferrer noopener\">anonymous access to many of the APIs<\/a>&nbsp;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the complete Magento 2 API call to get all store IDs, names, and codes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Method:&nbsp;<\/strong>GET<\/li>\n\n\n\n<li><strong>URL:&nbsp;<\/strong><em>store_url\/rest\/V1\/store\/storeGroups<\/em><\/li>\n\n\n\n<li><strong>Authorization Type:&nbsp;<\/strong>Bearer Token<\/li>\n\n\n\n<li><strong>Token:<\/strong>&lt;admin token&gt;<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2022\/04\/Magento-2-API-Get-All-Store-IDs-Name-Codes-700x410-1.png\" alt=\"Magento 2 API Get All Store IDs Name Codes 700x410\" class=\"wp-image-50322\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On calling the above request, you\u2019ll get all the store IDs, names, and codes in Magento 2 in the following format:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[\n    {\n        \"id\": 0,\n        \"website_id\": 0,\n        \"root_category_id\": 0,\n        \"default_store_id\": 0,\n        \"name\": \"Default\",\n        \"code\": \"default\"\n    },\n    {\n        \"id\": 1,\n        \"website_id\": 1,\n        \"root_category_id\": 2,\n        \"default_store_id\": 1,\n        \"name\": \"Main Website Store\",\n        \"code\": \"main_website_store\"\n    },\n    {\n        \"id\": 2,\n        \"website_id\": 3,\n        \"root_category_id\": 14,\n        \"default_store_id\": 2,\n        \"name\": \"new store\",\n        \"code\": \"new_store\"\n    }\n]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! This is how you can get all store IDs, names, and codes in Magento 2 through the API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you are&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/best-magento-2-app-builder\/\">developing a Magento 2 app<\/a>, 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In case you still have any queries or doubts regarding it, feel free to comment. I would be happy to help you.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share this Magento 2 API tutorial with your developer friends through social media!  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading.  <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-admin-token\/\">Magento 2 API &#8211; Get Admin Token<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-cms-page-content\/\">Magento 2 API &#8211; Get CMS Page Content<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, Magento peeps! In my last blog post on&nbsp;Magento 2 API, I provided complete tutorial to get admin token through API. In case you missed&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2540","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2540"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2540\/revisions"}],"predecessor-version":[{"id":12886,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2540\/revisions\/12886"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}