0

List Assigned Fulfillment Orders

by
Published Nov 8, 2023

List the fulfillment orders assigned to this app's fulfillment service locations.

Script shopify Verified

The script

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

3
/**
4
 * List Assigned Fulfillment Orders
5
 * For fulfillment service apps: list the fulfillment orders assigned to the app's locations, optionally filtered by request status (e.g. FULFILLMENT_REQUESTED to pick up new work, CANCELLATION_REQUESTED to see cancellations). Returns one page; pass pageInfo.endCursor as after for the next. Needs the read_assigned_fulfillment_orders scope.
6
 */
7
export async function main(
8
  auth: RT.Shopify,
9
  assignment_status:
10
    | "FULFILLMENT_REQUESTED"
11
    | "FULFILLMENT_ACCEPTED"
12
    | "CANCELLATION_REQUESTED"
13
    | "FULFILLMENT_UNSUBMITTED"
14
    | undefined,
15
  location_ids: string[] | undefined,
16
  sort_key: "UPDATED_AT" | "ID" | undefined,
17
  reverse: boolean | undefined,
18
  first: number | undefined,
19
  after: string | undefined
20
) {
21
  const response = await fetch(
22
    `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
23
    {
24
      method: "POST",
25
      headers: {
26
        "X-Shopify-Access-Token": auth.token,
27
        "Content-Type": "application/json",
28
        Accept: "application/json",
29
      },
30
      body: JSON.stringify({
31
        query: `query ($first: Int!, $after: String, $assignmentStatus: FulfillmentOrderAssignmentStatus, $locationIds: [ID!], $sortKey: FulfillmentOrderSortKeys, $reverse: Boolean) { assignedFulfillmentOrders(first: $first, after: $after, assignmentStatus: $assignmentStatus, locationIds: $locationIds, 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 } } }`,
32
        variables: {
33
          first: first || 50,
34
          after: after || undefined,
35
          assignmentStatus: assignment_status || undefined,
36
          locationIds: location_ids?.length
37
            ? location_ids.map((id) =>
38
                id.startsWith("gid://") ? id : `gid://shopify/Location/${id}`
39
              )
40
            : undefined,
41
          sortKey: sort_key || undefined,
42
          reverse: reverse || undefined,
43
        },
44
      }),
45
    }
46
  )
47

48
  if (!response.ok) {
49
    throw new Error(`${response.status} ${await response.text()}`)
50
  }
51

52
  const { data, errors } = await response.json()
53
  if (errors) {
54
    throw new Error(JSON.stringify(errors))
55
  }
56

57
  return data.assignedFulfillmentOrders
58
}
59

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