Create a new FulfillmentService

To create a fulfillment service, you can also use a cURL request that uses that fulfillment_service.

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
 * Create a new FulfillmentService
7
 * To create a fulfillment service, you can also use a cURL request that uses that fulfillment_service.
8
 */
9
export async function main(
10
  auth: Shopify,
11
  api_version: string = "2023-10",
12
  body: {
13
    fulfillment_service?: {
14
      callback_url?: string;
15
      format?: string;
16
      inventory_management?: boolean;
17
      name?: string;
18
      requires_shipping_method?: boolean;
19
      tracking_support?: boolean;
20
      [k: string]: unknown;
21
    };
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_services.json`
27
  );
28

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