1 | type Shopify = { |
2 | token: string; |
3 | store_name: string; |
4 | }; |
5 | |
6 | * Cancel a fulfillment order |
7 | * Marks a fulfillment order as cancelled. |
8 | */ |
9 | export async function main( |
10 | auth: Shopify, |
11 | api_version: string = "2023-10", |
12 | fulfillment_order_id: string, |
13 | body: { |
14 | fulfillment_order?: { |
15 | assigned_location?: { |
16 | address1?: { [k: string]: unknown }; |
17 | address2?: { [k: string]: unknown }; |
18 | city?: { [k: string]: unknown }; |
19 | country_code?: string; |
20 | location_id?: number; |
21 | name?: string; |
22 | phone?: { [k: string]: unknown }; |
23 | province?: { [k: string]: unknown }; |
24 | zip?: { [k: string]: unknown }; |
25 | [k: string]: unknown; |
26 | }; |
27 | assigned_location_id?: number; |
28 | destination?: { |
29 | address1?: string; |
30 | address2?: string; |
31 | city?: string; |
32 | company?: { [k: string]: unknown }; |
33 | country?: string; |
34 | email?: string; |
35 | first_name?: string; |
36 | id?: number; |
37 | last_name?: string; |
38 | phone?: string; |
39 | province?: string; |
40 | zip?: string; |
41 | [k: string]: unknown; |
42 | }; |
43 | fulfillment_service_handle?: string; |
44 | id?: number; |
45 | line_items?: { |
46 | fulfillable_quantity?: number; |
47 | fulfillment_order_id?: number; |
48 | id?: number; |
49 | inventory_item_id?: number; |
50 | line_item_id?: number; |
51 | quantity?: number; |
52 | shop_id?: number; |
53 | variant_id?: number; |
54 | [k: string]: unknown; |
55 | }[]; |
56 | merchant_requests?: unknown[]; |
57 | order_id?: number; |
58 | request_status?: string; |
59 | shop_id?: number; |
60 | status?: string; |
61 | supported_actions?: string[]; |
62 | [k: string]: unknown; |
63 | }; |
64 | [k: string]: unknown; |
65 | } |
66 | ) { |
67 | const url = new URL( |
68 | `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_orders/${fulfillment_order_id}/cancel.json` |
69 | ); |
70 |
|
71 | const response = await fetch(url, { |
72 | method: "POST", |
73 | headers: { |
74 | "Content-Type": "application/json", |
75 | "X-Shopify-Access-Token": auth.token, |
76 | }, |
77 | body: JSON.stringify(body), |
78 | }); |
79 | if (!response.ok) { |
80 | const text = await response.text(); |
81 | throw new Error(`${response.status} ${text}`); |
82 | } |
83 | return await response.json(); |
84 | } |
85 |
|