0

ListDisputes

by
Published Oct 17, 2025

Returns a list of disputes associated with a particular account.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListDisputes
7
 * Returns a list of disputes associated with a particular account.
8
 */
9
export async function main(
10
  auth: Square,
11
  cursor: string | undefined,
12
  states:
13
    | "INQUIRY_EVIDENCE_REQUIRED"
14
    | "INQUIRY_PROCESSING"
15
    | "INQUIRY_CLOSED"
16
    | "EVIDENCE_REQUIRED"
17
    | "PROCESSING"
18
    | "WON"
19
    | "LOST"
20
    | "ACCEPTED"
21
    | undefined,
22
  location_id: string | undefined,
23
) {
24
  const url = new URL(`https://connect.squareup.com/v2/disputes`);
25
  for (const [k, v] of [
26
    ["cursor", cursor],
27
    ["states", states],
28
    ["location_id", location_id],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47