0

UpsertBookingCustomAttribute

by
Published Oct 17, 2025

Upserts a bookings custom attribute. To call this endpoint with buyer-level permissions, set `APPOINTMENTS_WRITE` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope. For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to *Appointments Plus* or *Appointments Premium*.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * UpsertBookingCustomAttribute
7
 * Upserts a bookings custom attribute.
8

9
To call this endpoint with buyer-level permissions, set `APPOINTMENTS_WRITE` for the OAuth scope.
10
To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope.
11

12
For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to *Appointments Plus*
13
or *Appointments Premium*.
14
 */
15
export async function main(
16
  auth: Square,
17
  booking_id: string,
18
  key: string,
19
  body: {
20
    custom_attribute: {
21
      key?: string;
22
      value?: {};
23
      version?: number;
24
      visibility?:
25
        | "VISIBILITY_HIDDEN"
26
        | "VISIBILITY_READ_ONLY"
27
        | "VISIBILITY_READ_WRITE_VALUES";
28
      definition?: {
29
        key?: string;
30
        schema?: {};
31
        name?: string;
32
        description?: string;
33
        visibility?:
34
          | "VISIBILITY_HIDDEN"
35
          | "VISIBILITY_READ_ONLY"
36
          | "VISIBILITY_READ_WRITE_VALUES";
37
        version?: number;
38
        updated_at?: string;
39
        created_at?: string;
40
      };
41
      updated_at?: string;
42
      created_at?: string;
43
    };
44
    idempotency_key?: string;
45
  },
46
) {
47
  const url = new URL(
48
    `https://connect.squareup.com/v2/bookings/${booking_id}/custom-attributes/${key}`,
49
  );
50

51
  const response = await fetch(url, {
52
    method: "PUT",
53
    headers: {
54
      "Content-Type": "application/json",
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: JSON.stringify(body),
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65