Retrieves fulfillments associated with an order
One script reply has been approved by the moderators Verified

Retrieves fulfillments associated with an order. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.

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
 * Retrieves fulfillments associated with an order
7
 * Retrieves fulfillments associated with an order. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  order_id: string,
13
  created_at_max: string | undefined,
14
  created_at_min: string | undefined,
15
  fields: string | undefined,
16
  limit: string | undefined,
17
  since_id: string | undefined,
18
  updated_at_max: string | undefined,
19
  updated_at_min: string | undefined
20
) {
21
  const url = new URL(
22
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/fulfillments.json`
23
  );
24
  for (const [k, v] of [
25
    ["created_at_max", created_at_max],
26
    ["created_at_min", created_at_min],
27
    ["fields", fields],
28
    ["limit", limit],
29
    ["since_id", since_id],
30
    ["updated_at_max", updated_at_max],
31
    ["updated_at_min", updated_at_min],
32
  ]) {
33
    if (v !== undefined && v !== "") {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      "X-Shopify-Access-Token": auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50