0

RetrieveBookingCustomAttribute

by
Published Oct 17, 2025

Retrieves a bookings custom attribute. 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
 * RetrieveBookingCustomAttribute
7
 * Retrieves a bookings custom attribute.
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
  key: string,
16
  with_definition: string | undefined,
17
  version: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://connect.squareup.com/v2/bookings/${booking_id}/custom-attributes/${key}`,
21
  );
22
  for (const [k, v] of [
23
    ["with_definition", with_definition],
24
    ["version", version],
25
  ]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + 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