0

ListBookings

by
Published Oct 17, 2025

Retrieve a collection of bookings. To call this endpoint with buyer-level permissions, set `APPOINTMENTS_READ` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListBookings
7
 * Retrieve a collection of bookings.
8

9
To call this endpoint with buyer-level permissions, set `APPOINTMENTS_READ` for the OAuth scope.
10
To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope.
11
 */
12
export async function main(
13
  auth: Square,
14
  limit: string | undefined,
15
  cursor: string | undefined,
16
  customer_id: string | undefined,
17
  team_member_id: string | undefined,
18
  location_id: string | undefined,
19
  start_at_min: string | undefined,
20
  start_at_max: string | undefined,
21
) {
22
  const url = new URL(`https://connect.squareup.com/v2/bookings`);
23
  for (const [k, v] of [
24
    ["limit", limit],
25
    ["cursor", cursor],
26
    ["customer_id", customer_id],
27
    ["team_member_id", team_member_id],
28
    ["location_id", location_id],
29
    ["start_at_min", start_at_min],
30
    ["start_at_max", start_at_max],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + 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