1 | |
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 |
|