Return a list of all disputes

Retrieve all disputes ordered by initiated_at date and time (ISO 8601 format), with the most recent being first. 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
 * Return a list of all disputes
7
 * Retrieve all disputes ordered by initiated_at date and time (ISO 8601 format), with the most recent being first. 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
  since_id: string | undefined,
13
  last_id: string | undefined,
14
  status: string | undefined,
15
  initiated_at: string | undefined
16
) {
17
  const url = new URL(
18
    `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/shopify_payments/disputes.json`
19
  );
20
  for (const [k, v] of [
21
    ["since_id", since_id],
22
    ["last_id", last_id],
23
    ["status", status],
24
    ["initiated_at", initiated_at],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      "X-Shopify-Access-Token": auth.token,
34
    },
35
    body: undefined,
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