How to get the default location using the REST API?

Topic summary

A developer needed to identify the default/primary location in a Shopify store via API, as the REST API’s location endpoint doesn’t include a default location indicator.

Initial Solution:

  • The primary_location_id field was available in the Shop object via REST API.

Current Issue:

  • Both REST and GraphQL APIs have deprecated the primary_location_id field in recent versions (2024-04 onwards).

Working Solution:

  • Query the GraphQL location endpoint without providing an ID parameter.
  • When no ID is specified, it automatically returns the primary/default location.
  • This behavior is documented in the official Shopify GraphQL API documentation.

The thread includes a code snippet demonstrating the GraphQL query. The solution was confirmed working by another developer.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

In the Shopify store admin panel, you can set Default Location. And in the UI, the default location has Default tag showing up. However, when I look at the REST API to retrieve a list of locations (https://shopify.dev/docs/api/admin-rest/2023-10/resources/location#get-locations), there is no way for me to find out which one is the default location. Can anyone help?

4 Likes

Looking for the same.

You get can it from the shop object under primary_location_id

https://shopify.dev/docs/api/admin-rest/2023-10/resources/shop

3 Likes

Looks like in the latest REST API and GQL API have primary location fields deprecated.

REST API:

https://shopify.dev/docs/api/admin-rest/2024-04/resources/shop

GQL API:

https://shopify.dev/docs/api/admin-graphql/2024-04/queries/location

How do we find this information in a new way now?

2 Likes

I found out: you query “location”, and it always returns the default one:

query defaultLocation {
  location {
    id
    name
  }
}

This is mentioned in the documentation: https://shopify.dev/docs/api/admin-graphql/2024-10/queries/location

If no ID is provided, the primary location of the Shop is returned.

1 Like

@binarydata thanks man, you saved my day :slightly_smiling_face: