Receive a list of all FulfillmentServices
One script reply has been approved by the moderators Verified

Receive a list of all FulfillmentServices

Created by hugo697 883 days ago Picked 1 time
Submitted by hugo697 Typescript (fetch-only)
Verified 337 days ago
1
type Shopify = {
2
  token: string;
3
  store_name: string;
4
};
5
/**
6
 * Receive a list of all FulfillmentServices
7
 * Receive a list of all FulfillmentServices
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  scope: string | undefined
13
) {
14
  const url = new URL(
15
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_services.json`
16
  );
17
  for (const [k, v] of [["scope", scope]]) {
18
    if (v !== undefined && v !== "") {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      "X-Shopify-Access-Token": auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35