1 | |
2 |
|
3 | |
4 | * List Locations |
5 | * List the store's inventory locations (warehouses, retail stores, fulfillment apps). Filter with Shopify's search syntax (e.g. `name:Warehouse`, `active:true`). Returns one page; pass pageInfo.endCursor as after for the next. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Shopify, |
9 | query: string | undefined, |
10 | include_inactive: boolean | undefined, |
11 | first: number | undefined, |
12 | after: string | undefined |
13 | ) { |
14 | const response = await fetch( |
15 | `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`, |
16 | { |
17 | method: "POST", |
18 | headers: { |
19 | "X-Shopify-Access-Token": auth.token, |
20 | "Content-Type": "application/json", |
21 | Accept: "application/json", |
22 | }, |
23 | body: JSON.stringify({ |
24 | query: `query ($first: Int!, $after: String, $query: String, $includeInactive: Boolean) { locations(first: $first, after: $after, query: $query, includeInactive: $includeInactive) { nodes { id legacyResourceId name isActive fulfillsOnlineOrders shipsInventory hasActiveInventory createdAt updatedAt address { address1 address2 city province provinceCode zip country countryCode phone formatted } } pageInfo { hasNextPage endCursor } } }`, |
25 | variables: { |
26 | first: first || 50, |
27 | after: after || undefined, |
28 | query: query || undefined, |
29 | includeInactive: include_inactive || undefined, |
30 | }, |
31 | }), |
32 | } |
33 | ) |
34 |
|
35 | if (!response.ok) { |
36 | throw new Error(`${response.status} ${await response.text()}`) |
37 | } |
38 |
|
39 | const { data, errors } = await response.json() |
40 | if (errors) { |
41 | throw new Error(JSON.stringify(errors)) |
42 | } |
43 |
|
44 | return data.locations |
45 | } |
46 |
|