0

List Fulfillment Orders

by
Published Nov 8, 2023

List fulfillment orders shop-wide, or for one order.

Script shopify Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * List Fulfillment Orders
5
 * List fulfillment orders across the shop (filtered with Shopify's search syntax, e.g. `status:open`), or the fulfillment orders of one order when order_id is set. Each one shows its status, holds, supported actions and line item ids (the first 10). Returns one page; pass pageInfo.endCursor as after for the next. Needs the read_merchant_managed_fulfillment_orders scope (plus read_assigned/read_third_party for other locations).
6
 */
7
export async function main(
8
  auth: RT.Shopify,
9
  order_id: string | undefined,
10
  query: string | undefined,
11
  include_closed: boolean | undefined,
12
  sort_key: "UPDATED_AT" | "ID" | undefined,
13
  reverse: boolean | undefined,
14
  first: number | undefined,
15
  after: string | undefined
16
) {
17
  const response = await fetch(
18
    `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
19
    {
20
      method: "POST",
21
      headers: {
22
        "X-Shopify-Access-Token": auth.token,
23
        "Content-Type": "application/json",
24
        Accept: "application/json",
25
      },
26
      body: JSON.stringify(
27
        order_id
28
          ? {
29
              query: `query ($id: ID!, $first: Int!, $after: String, $query: String, $reverse: Boolean) { order(id: $id) { fulfillmentOrders(first: $first, after: $after, query: $query, reverse: $reverse) { nodes { id status requestStatus orderId orderName createdAt updatedAt fulfillAt fulfillBy assignedLocation { name location { id } } fulfillmentHolds { id reason reasonNotes handle } supportedActions { action } lineItems(first: 10) { nodes { id sku productTitle variantTitle totalQuantity remainingQuantity lineItem { id } } } } pageInfo { hasNextPage endCursor } } } }`,
30
              variables: {
31
                id: order_id.startsWith("gid://")
32
                  ? order_id
33
                  : `gid://shopify/Order/${order_id}`,
34
                first: first || 50,
35
                after: after || undefined,
36
                query: query || undefined,
37
                reverse: reverse || undefined,
38
              },
39
            }
40
          : {
41
              query: `query ($first: Int!, $after: String, $query: String, $includeClosed: Boolean, $sortKey: FulfillmentOrderSortKeys, $reverse: Boolean) { fulfillmentOrders(first: $first, after: $after, query: $query, includeClosed: $includeClosed, sortKey: $sortKey, reverse: $reverse) { nodes { id status requestStatus orderId orderName createdAt updatedAt fulfillAt fulfillBy assignedLocation { name location { id } } fulfillmentHolds { id reason reasonNotes handle } supportedActions { action } lineItems(first: 10) { nodes { id sku productTitle variantTitle totalQuantity remainingQuantity lineItem { id } } } } pageInfo { hasNextPage endCursor } } }`,
42
              variables: {
43
                first: first || 50,
44
                after: after || undefined,
45
                query: query || undefined,
46
                includeClosed: include_closed || undefined,
47
                sortKey: sort_key || undefined,
48
                reverse: reverse || undefined,
49
              },
50
            }
51
      ),
52
    }
53
  )
54

55
  if (!response.ok) {
56
    throw new Error(`${response.status} ${await response.text()}`)
57
  }
58

59
  const { data, errors } = await response.json()
60
  if (errors) {
61
    throw new Error(JSON.stringify(errors))
62
  }
63

64
  if (order_id) {
65
    if (!data.order) {
66
      throw new Error(`Order ${order_id} not found`)
67
    }
68
    return data.order.fulfillmentOrders
69
  }
70

71
  return data.fulfillmentOrders
72
}
73

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 fulfillment orders for a specific order
    7
     * Retrieves a list of fulfillment orders for a specific order.
    8
     */
    9
    export async function main(
    10
      auth: Shopify,
    11
      api_version: string = "2023-10",
    12
      order_id: string
    13
    ) {
    14
      const url = new URL(
    15
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/fulfillment_orders.json`
    16
      );
    17
    
    
    18
      const response = await fetch(url, {
    19
        method: "GET",
    20
        headers: {
    21
          "X-Shopify-Access-Token": auth.token,
    22
        },
    23
        body: undefined,
    24
      });
    25
      if (!response.ok) {
    26
        const text = await response.text();
    27
        throw new Error(`${response.status} ${text}`);
    28
      }
    29
      return await response.json();
    30
    }
    31