Retrieves a list of abandoned checkouts

Retrieves a list of abandoned checkouts. 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.

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
 * Retrieves a list of abandoned checkouts
7
 * Retrieves a list of abandoned checkouts. 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
  limit: string | undefined,
13
  since_id: string | undefined,
14
  created_at_min: string | undefined,
15
  created_at_max: string | undefined,
16
  updated_at_min: string | undefined,
17
  updated_at_max: string | undefined,
18
  status: string | undefined
19
) {
20
  const url = new URL(
21
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/checkouts.json`
22
  );
23
  for (const [k, v] of [
24
    ["limit", limit],
25
    ["since_id", since_id],
26
    ["created_at_min", created_at_min],
27
    ["created_at_max", created_at_max],
28
    ["updated_at_min", updated_at_min],
29
    ["updated_at_max", updated_at_max],
30
    ["status", status],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      "X-Shopify-Access-Token": auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49