0

SearchAvailability

by
Published Oct 17, 2025

Searches for availabilities for booking. 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
 * SearchAvailability
7
 * Searches for availabilities for booking.
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
  body: {
15
    query: {
16
      filter: {
17
        start_at_range: { start_at?: string; end_at?: string };
18
        location_id?: string;
19
        segment_filters?: {
20
          service_variation_id: string;
21
          team_member_id_filter?: {
22
            all?: string[];
23
            any?: string[];
24
            none?: string[];
25
          };
26
        }[];
27
        booking_id?: string;
28
      };
29
    };
30
  },
31
) {
32
  const url = new URL(
33
    `https://connect.squareup.com/v2/bookings/availability/search`,
34
  );
35

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