locationquery
query
2025-01release candidate
Returns an inventory Location resource by ID.
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?
Location possible returns
Represents the location where the physical good resides.
Was this section helpful?
Examples
Hide code
DescriptionCopy
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/2025-01/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();
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)
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" }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $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]);
Hide code
Input variables
Copy
{ "namespace": "my_fields", "key": "hours", "ownerId": "gid://shopify/Location/346779380" }
Hide code
Response
JSON
{ "location": { "hours": { "value": "Open daily 9AM-5PM" } } }