0

Get Fulfillment

by
Published Nov 8, 2023

Get a fulfillment by numeric ID or GID: status, tracking info, delivery dates, location, line items and the fulfillment orders it fulfilled.

Script shopify Verified

The script

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

3
/**
4
 * Get Fulfillment
5
 * Get a fulfillment by numeric ID or GID: status, tracking info, delivery dates, location, line items and the fulfillment orders it fulfilled.
6
 */
7
export async function main(auth: RT.Shopify, fulfillment_id: string) {
8
  const response = await fetch(
9
    `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
10
    {
11
      method: "POST",
12
      headers: {
13
        "X-Shopify-Access-Token": auth.token,
14
        "Content-Type": "application/json",
15
        Accept: "application/json",
16
      },
17
      body: JSON.stringify({
18
        query: `query ($id: ID!) { fulfillment(id: $id) { id legacyResourceId name status displayStatus createdAt updatedAt deliveredAt estimatedDeliveryAt inTransitAt totalQuantity requiresShipping trackingInfo { company number url } location { id name } order { id name } service { handle serviceName } fulfillmentLineItems(first: 250) { nodes { id quantity lineItem { id name sku } } } fulfillmentOrders(first: 10) { nodes { id status } } } }`,
19
        variables: {
20
          id: fulfillment_id.startsWith("gid://")
21
            ? fulfillment_id
22
            : `gid://shopify/Fulfillment/${fulfillment_id}`,
23
        },
24
      }),
25
    }
26
  )
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  const { data, errors } = await response.json()
33
  if (errors) {
34
    throw new Error(JSON.stringify(errors))
35
  }
36

37
  if (!data.fulfillment) {
38
    throw new Error(`Fulfillment ${fulfillment_id} not found`)
39
  }
40

41
  return data.fulfillment
42
}
43

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
     * Receive a single Fulfillment
    7
     * Retrieve a specific fulfillment
    8
     */
    9
    export async function main(
    10
      auth: Shopify,
    11
      api_version: string = "2023-10",
    12
      order_id: string,
    13
      fulfillment_id: string,
    14
      fields: string | undefined
    15
    ) {
    16
      const url = new URL(
    17
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/fulfillments/${fulfillment_id}.json`
    18
      );
    19
      for (const [k, v] of [["fields", fields]]) {
    20
        if (v !== undefined && v !== "") {
    21
          url.searchParams.append(k, v);
    22
        }
    23
      }
    24
      const response = await fetch(url, {
    25
        method: "GET",
    26
        headers: {
    27
          "X-Shopify-Access-Token": auth.token,
    28
        },
    29
        body: undefined,
    30
      });
    31
      if (!response.ok) {
    32
        const text = await response.text();
    33
        throw new Error(`${response.status} ${text}`);
    34
      }
    35
      return await response.json();
    36
    }
    37