0

UpdateBookingCustomAttributeDefinition

by
Published Oct 17, 2025

Updates a bookings custom attribute definition. 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
 * UpdateBookingCustomAttributeDefinition
7
 * Updates a bookings custom attribute definition.
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
  key: string,
18
  body: {
19
    custom_attribute_definition: {
20
      key?: string;
21
      schema?: {};
22
      name?: string;
23
      description?: string;
24
      visibility?:
25
        | "VISIBILITY_HIDDEN"
26
        | "VISIBILITY_READ_ONLY"
27
        | "VISIBILITY_READ_WRITE_VALUES";
28
      version?: number;
29
      updated_at?: string;
30
      created_at?: string;
31
    };
32
    idempotency_key?: string;
33
  },
34
) {
35
  const url = new URL(
36
    `https://connect.squareup.com/v2/bookings/custom-attribute-definitions/${key}`,
37
  );
38

39
  const response = await fetch(url, {
40
    method: "PUT",
41
    headers: {
42
      "Content-Type": "application/json",
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53