Rejects a fulfillment request
One script reply has been approved by the moderators Verified

Rejects a fulfillment request sent to a fulfillment service for a fulfillment order.

Created by hugo697 883 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 337 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Rejects a fulfillment request
7
 * Rejects a fulfillment request sent to a fulfillment service for a fulfillment order.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  fulfillment_order_id: string,
13
  body: {
14
    fulfillment_request?: { message?: string; [k: string]: unknown };
15
    [k: string]: unknown;
16
  }
17
) {
18
  const url = new URL(
19
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_orders/${fulfillment_order_id}/fulfillment_request/reject.json`
20
  );
21

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