0

List Locations

by
Published Nov 8, 2023

List the store's inventory locations.

Script shopify Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
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

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Shopify = {
    2
      token: string;
    3
      store_name: string;
    4
    };
    5
    /**
    6
     * Retrieves a list of locations
    7
     * Retrieves a list of locations
    8
     */
    9
    export async function main(auth: Shopify, api_version: string = "2023-10") {
    10
      const url = new URL(
    11
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/locations.json`
    12
      );
    13
    
    
    14
      const response = await fetch(url, {
    15
        method: "GET",
    16
        headers: {
    17
          "X-Shopify-Access-Token": auth.token,
    18
        },
    19
        body: undefined,
    20
      });
    21
      if (!response.ok) {
    22
        const text = await response.text();
    23
        throw new Error(`${response.status} ${text}`);
    24
      }
    25
      return await response.json();
    26
    }
    27