0

Creates a fulfillment for one or many fulfillment orders

by
Published Nov 8, 2023

Creates a fulfillment for one or many fulfillment orders. The fulfillment orders are associated with the same order and are assigned to the same location.

Script shopify Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Creates a fulfillment for one or many fulfillment orders
7
 * Creates a fulfillment for one or many fulfillment orders. The fulfillment orders are associated with the same order and are assigned to the same location.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  body: {
13
    fulfillment?: {
14
      line_items_by_fulfillment_order?: {
15
        fulfillment_order_id?: number;
16
        [k: string]: unknown;
17
      }[];
18
      message?: string;
19
      notify_customer?: boolean;
20
      tracking_info?: {
21
        company?: string;
22
        number?: number;
23
        url?: string;
24
        [k: string]: unknown;
25
      };
26
      [k: string]: unknown;
27
    };
28
    [k: string]: unknown;
29
  }
30
) {
31
  const url = new URL(
32
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillments.json`
33
  );
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "Content-Type": "application/json",
39
      "X-Shopify-Access-Token": auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49