0

ListBookingCustomAttributes

by
Published Oct 17, 2025

Lists a booking's custom attributes. 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
 * ListBookingCustomAttributes
7
 * Lists a booking's custom attributes.
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
  booking_id: string,
15
  limit: string | undefined,
16
  cursor: string | undefined,
17
  with_definitions: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://connect.squareup.com/v2/bookings/${booking_id}/custom-attributes`,
21
  );
22
  for (const [k, v] of [
23
    ["limit", limit],
24
    ["cursor", cursor],
25
    ["with_definitions", with_definitions],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44