0

ListCustomers

by
Published Oct 17, 2025

Lists customer profiles associated with a Square account. Under normal operating conditions, newly created or updated customer profiles become available for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListCustomers
7
 * Lists customer profiles associated with a Square account.
8

9
Under normal operating conditions, newly created or updated customer profiles become available
10
for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated
11
profiles can take closer to one minute or longer, especially during network incidents and outages.
12
 */
13
export async function main(
14
  auth: Square,
15
  cursor: string | undefined,
16
  limit: string | undefined,
17
  sort_field: "DEFAULT" | "CREATED_AT" | undefined,
18
  sort_order: "DESC" | "ASC" | undefined,
19
  count: string | undefined,
20
) {
21
  const url = new URL(`https://connect.squareup.com/v2/customers`);
22
  for (const [k, v] of [
23
    ["cursor", cursor],
24
    ["limit", limit],
25
    ["sort_field", sort_field],
26
    ["sort_order", sort_order],
27
    ["count", count],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46