0

CreateBookingCustomAttributeDefinition

by
Published Oct 17, 2025

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

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