Anchor to location
location
query
Returns an inventory Location resource by ID.
Anchor to Arguments
Arguments
- •
The ID of the location to return. If no ID is provided, the primary location of the Shop is returned.
Was this section helpful?
Anchor to Possible returnsPossible returns
- Anchor to LocationLocation•
Represents the location where the physical good resides. You can stock inventory at active locations. Active locations that have
and are configured with a shipping rate, pickup enabled or local delivery will be able to sell from their storefront.
Was this section helpful?
- Get a metafield attached to a location
- Get metafields attached to a location
- Get pinned metafield definitions associated with a location
- Retrieve a list of inventory levels for a location
- Retrieve a single location by its ID
- Returns a Location resource by ID
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) {6 location(id: $ownerId) {7 hours: metafield(namespace: $namespace, key: $key) {8 value9 }10 }11 }`,12 {13 variables: {14 "namespace": "my_fields",15 "key": "hours",16 "ownerId": "gid://shopify/Location/346779380"17 },18 },19);2021const data = await response.json();22
query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
location(id: $ownerId) {
hours: metafield(namespace: $namespace, key: $key) {
value
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) { location(id: $ownerId) { hours: metafield(namespace: $namespace, key: $key) { value } } }",
"variables": {
"namespace": "my_fields",
"key": "hours",
"ownerId": "gid://shopify/Location/346779380"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
location(id: $ownerId) {
hours: metafield(namespace: $namespace, key: $key) {
value
}
}
}`,
{
variables: {
"namespace": "my_fields",
"key": "hours",
"ownerId": "gid://shopify/Location/346779380"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
location(id: $ownerId) {
hours: metafield(namespace: $namespace, key: $key) {
value
}
}
}`,
"variables": {
"namespace": "my_fields",
"key": "hours",
"ownerId": "gid://shopify/Location/346779380"
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
query LocationMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
location(id: $ownerId) {
hours: metafield(namespace: $namespace, key: $key) {
value
}
}
}
QUERY
variables = {
"namespace": "my_fields",
"key": "hours",
"ownerId": "gid://shopify/Location/346779380"
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "namespace": "my_fields",3 "key": "hours",4 "ownerId": "gid://shopify/Location/346779380"5}
Response
JSON1{2 "location": {3 "hours": {4 "value": "Open daily 9AM-5PM"5 }6 }7}