0

CreateBreakType

by
Published Oct 17, 2025

Creates a new `BreakType`. A `BreakType` is a template for creating `Break` objects. You must provide the following values in your request to this endpoint: - `location_id` - `break_name` - `expected_duration` - `is_paid` You can only have three `BreakType` instances per location. If you attempt to add a fourth `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location." is returned.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CreateBreakType
7
 * Creates a new `BreakType`.
8

9
A `BreakType` is a template for creating `Break` objects.
10
You must provide the following values in your request to this
11
endpoint:
12

13
- `location_id`
14
- `break_name`
15
- `expected_duration`
16
- `is_paid`
17

18
You can only have three `BreakType` instances per location. If you attempt to add a fourth
19
`BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location."
20
is returned.
21
 */
22
export async function main(
23
  auth: Square,
24
  body: {
25
    idempotency_key?: string;
26
    break_type: {
27
      id?: string;
28
      location_id: string;
29
      break_name: string;
30
      expected_duration: string;
31
      is_paid: false | true;
32
      version?: number;
33
      created_at?: string;
34
      updated_at?: string;
35
    };
36
  },
37
) {
38
  const url = new URL(`https://connect.squareup.com/v2/labor/break-types`);
39

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