1 | |
2 |
|
3 | |
4 | * Release Fulfillment Order Hold |
5 | * Release holds on a fulfillment order so it can be fulfilled. Leave hold_ids empty to release every hold the app placed. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Shopify, |
9 | fulfillment_order_id: string, |
10 | hold_ids: string[] | undefined |
11 | ) { |
12 | const response = await fetch( |
13 | `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`, |
14 | { |
15 | method: "POST", |
16 | headers: { |
17 | "X-Shopify-Access-Token": auth.token, |
18 | "Content-Type": "application/json", |
19 | Accept: "application/json", |
20 | }, |
21 | body: JSON.stringify({ |
22 | query: `mutation ($id: ID!, $holdIds: [ID!]) { fulfillmentOrderReleaseHold(id: $id, holdIds: $holdIds) { fulfillmentOrder { id status fulfillmentHolds { id reason } } userErrors { field message } } }`, |
23 | variables: { |
24 | id: fulfillment_order_id.startsWith("gid://") |
25 | ? fulfillment_order_id |
26 | : `gid://shopify/FulfillmentOrder/${fulfillment_order_id}`, |
27 | holdIds: hold_ids?.length |
28 | ? hold_ids.map((id) => |
29 | id.startsWith("gid://") |
30 | ? id |
31 | : `gid://shopify/FulfillmentHold/${id}` |
32 | ) |
33 | : undefined, |
34 | }, |
35 | }), |
36 | } |
37 | ) |
38 |
|
39 | if (!response.ok) { |
40 | throw new Error(`${response.status} ${await response.text()}`) |
41 | } |
42 |
|
43 | const { data, errors } = await response.json() |
44 | if (errors) { |
45 | throw new Error(JSON.stringify(errors)) |
46 | } |
47 |
|
48 | if (data.fulfillmentOrderReleaseHold.userErrors.length) { |
49 | throw new Error(JSON.stringify(data.fulfillmentOrderReleaseHold.userErrors)) |
50 | } |
51 |
|
52 | return data.fulfillmentOrderReleaseHold |
53 | } |
54 |
|