Transition a fulfillment from pending to open.

Mark a fulfillment as open

Script shopify Verified

by hugo697 ยท 11/8/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Transition a fulfillment from pending to open.
7
 * Mark a fulfillment as open
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  order_id: string,
13
  fulfillment_id: string,
14
  body: { [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/fulfillments/${fulfillment_id}/open.json`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "Content-Type": "application/json",
24
      "X-Shopify-Access-Token": auth.token,
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34