Magento 2 API: Get Stores Information

In this article, we will be looking into how we can get the store information in Magento 2 using its API.

  • We will be fetching websites, stores, and store views.
  • We will also be fetching the store configs that include the locale, timezone, currency code, and store URLs.

Anonymouse APIs Restriction

The REST endpoints to get the stores’ information falls under the anonymous APIs category. However, in the recent Magento version, those API endpoints are restricted. They need “admin” or “integration” token to authenticate.

If you need/want to bypass the token authentication for those APIs, you can disable this feature by going to:

Magento Admin > STORES > Settings > Configuration > Services > Magento Web API > Web API Security > Allow Anonymous Guest Access = Yes.

NOTE:

  • We will be passing the admin bearer token to authenticate the APIs.
  • This article shows how we can get the admin token in Magento: Magento 2 API: Get Admin Token

In our example Magento admin, we have two websites, two stores, and two store views. We will be using Magento APIs to get these websites, stores, and store views.

all stores magento

Get Websites

API Doc:
https://adobe-commerce.redoc.ly/2.4.5-admin/tag/storewebsites

Endpoint:


GET <host>/rest/V1/store/websites

Authentication Bearer Token:


<admin-token>

Response:


[
    {
        "id": 0,
        "code": "admin",
        "name": "Admin",
        "default_group_id": 0
    },
    {
        "id": 1,
        "code": "base",
        "name": "Main Website",
        "default_group_id": 1
    },
    {
        "id": 2,
        "code": "second_website",
        "name": "Second Website",
        "default_group_id": 2
    }
]

Get Websites using cURL Request


curl --location --request GET '<host>/rest/V1/store/websites' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNxxxxx'

Get Stores

API Doc:
https://adobe-commerce.redoc.ly/2.4.5-admin/tag/storestoreGroups

Endpoint:


GET <host>/rest/V1/store/storeGroups

Authentication Bearer Token:


<admin-token>

Response:


[
    {
        "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": 2,
        "root_category_id": 2,
        "default_store_id": 2,
        "name": "Second Store",
        "code": "second_store"
    }
]

Get Stores using cURL Request


curl --location --request GET '<host>/rest/V1/store/storeGroups' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNxxxxx'

Get Store Views

API Doc:
https://adobe-commerce.redoc.ly/2.4.5-admin/tag/storestoreViews

Endpoint:


GET <host>/rest/V1/store/storeViews

Authentication Bearer Token:


<admin-token>

Response:


[
    {
        "id": 1,
        "code": "default",
        "name": "Default Store View",
        "website_id": 1,
        "store_group_id": 1,
        "is_active": 1
    },
    {
        "id": 0,
        "code": "admin",
        "name": "Admin",
        "website_id": 0,
        "store_group_id": 0,
        "is_active": 1
    },
    {
        "id": 2,
        "code": "second_store_view",
        "name": "Second Store View",
        "website_id": 2,
        "store_group_id": 2,
        "is_active": 1
    }
]

Get Websites using cURL Request


curl --location --request GET '<host>/rest/V1/store/storeViews' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNxxxxx'

Get Store Configs

API Doc:
https://adobe-commerce.redoc.ly/2.4.5-admin/tag/storestoreConfigs

Get store configuration values like locale, store URLs, timezone, etc.

Endpoint:


GET <host>/rest/V1/store/storeConfigs

Authentication Bearer Token:


<admin-token>

Response:


[
    {
        "id": 1,
        "code": "default",
        "website_id": 1,
        "locale": "en_US",
        "base_currency_code": "USD",
        "default_display_currency_code": "USD",
        "timezone": "America/Los_Angeles",
        "weight_unit": "lbs",
        "base_url": "https://app.your-project.test/",
        "base_link_url": "https://app.your-project.test/",
        "base_static_url": "https://app.your-project.test/static/",
        "base_media_url": "https://app.your-project.test/media/",
        "secure_base_url": "https://app.your-project.test/",
        "secure_base_link_url": "https://app.your-project.test/",
        "secure_base_static_url": "https://app.your-project.test/static/",
        "secure_base_media_url": "https://app.your-project.test/media/"
    },
    {
        "id": 2,
        "code": "second_store_view",
        "website_id": 2,
        "locale": "en_US",
        "base_currency_code": "USD",
        "default_display_currency_code": "USD",
        "timezone": "America/Los_Angeles",
        "weight_unit": "lbs",
        "base_url": "https://app.your-project.test/",
        "base_link_url": "https://app.your-project.test/",
        "base_static_url": "https://app.your-project.test/static/",
        "base_media_url": "https://app.your-project.test/media/",
        "secure_base_url": "https://app.your-project.test/",
        "secure_base_link_url": "https://app.your-project.test/",
        "secure_base_static_url": "https://app.your-project.test/static/",
        "secure_base_media_url": "https://app.your-project.test/media/"
    }
]

Get Websites using cURL Request


curl --location --request GET '<host>/rest/V1/store/storeConfigs' \
--header 'Authorization: Bearer eyJraWQiOiIxIiwiYWxnIjoiSFMyNxxxxx'

Hope this helps. Thanks.

Magento REST API Reference: https://developer.adobe.com/commerce/webapi/rest/quick-reference/