0

UpdateBooking

by
Published Oct 17, 2025

Updates a booking. 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
 * UpdateBooking
7
 * Updates a booking.
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
  body: {
19
    idempotency_key?: string;
20
    booking: {
21
      id?: string;
22
      version?: number;
23
      status?:
24
        | "PENDING"
25
        | "CANCELLED_BY_CUSTOMER"
26
        | "CANCELLED_BY_SELLER"
27
        | "DECLINED"
28
        | "ACCEPTED"
29
        | "NO_SHOW";
30
      created_at?: string;
31
      updated_at?: string;
32
      start_at?: string;
33
      location_id?: string;
34
      customer_id?: string;
35
      customer_note?: string;
36
      seller_note?: string;
37
      appointment_segments?: {
38
        duration_minutes?: number;
39
        service_variation_id?: string;
40
        team_member_id: string;
41
        service_variation_version?: number;
42
        intermission_minutes?: number;
43
        any_team_member?: false | true;
44
        resource_ids?: string[];
45
      }[];
46
      transition_time_minutes?: number;
47
      all_day?: false | true;
48
      location_type?: "BUSINESS_LOCATION" | "CUSTOMER_LOCATION" | "PHONE";
49
      creator_details?: {
50
        creator_type?: "TEAM_MEMBER" | "CUSTOMER";
51
        team_member_id?: string;
52
        customer_id?: string;
53
      };
54
      source?:
55
        | "FIRST_PARTY_MERCHANT"
56
        | "FIRST_PARTY_BUYER"
57
        | "THIRD_PARTY_BUYER"
58
        | "API";
59
      address?: {
60
        address_line_1?: string;
61
        address_line_2?: string;
62
        address_line_3?: string;
63
        locality?: string;
64
        sublocality?: string;
65
        sublocality_2?: string;
66
        sublocality_3?: string;
67
        administrative_district_level_1?: string;
68
        administrative_district_level_2?: string;
69
        administrative_district_level_3?: string;
70
        postal_code?: string;
71
        country?:
72
          | "ZZ"
73
          | "AD"
74
          | "AE"
75
          | "AF"
76
          | "AG"
77
          | "AI"
78
          | "AL"
79
          | "AM"
80
          | "AO"
81
          | "AQ"
82
          | "AR"
83
          | "AS"
84
          | "AT"
85
          | "AU"
86
          | "AW"
87
          | "AX"
88
          | "AZ"
89
          | "BA"
90
          | "BB"
91
          | "BD"
92
          | "BE"
93
          | "BF"
94
          | "BG"
95
          | "BH"
96
          | "BI"
97
          | "BJ"
98
          | "BL"
99
          | "BM"
100
          | "BN"
101
          | "BO"
102
          | "BQ"
103
          | "BR"
104
          | "BS"
105
          | "BT"
106
          | "BV"
107
          | "BW"
108
          | "BY"
109
          | "BZ"
110
          | "CA"
111
          | "CC"
112
          | "CD"
113
          | "CF"
114
          | "CG"
115
          | "CH"
116
          | "CI"
117
          | "CK"
118
          | "CL"
119
          | "CM"
120
          | "CN"
121
          | "CO"
122
          | "CR"
123
          | "CU"
124
          | "CV"
125
          | "CW"
126
          | "CX"
127
          | "CY"
128
          | "CZ"
129
          | "DE"
130
          | "DJ"
131
          | "DK"
132
          | "DM"
133
          | "DO"
134
          | "DZ"
135
          | "EC"
136
          | "EE"
137
          | "EG"
138
          | "EH"
139
          | "ER"
140
          | "ES"
141
          | "ET"
142
          | "FI"
143
          | "FJ"
144
          | "FK"
145
          | "FM"
146
          | "FO"
147
          | "FR"
148
          | "GA"
149
          | "GB"
150
          | "GD"
151
          | "GE"
152
          | "GF"
153
          | "GG"
154
          | "GH"
155
          | "GI"
156
          | "GL"
157
          | "GM"
158
          | "GN"
159
          | "GP"
160
          | "GQ"
161
          | "GR"
162
          | "GS"
163
          | "GT"
164
          | "GU"
165
          | "GW"
166
          | "GY"
167
          | "HK"
168
          | "HM"
169
          | "HN"
170
          | "HR"
171
          | "HT"
172
          | "HU"
173
          | "ID"
174
          | "IE"
175
          | "IL"
176
          | "IM"
177
          | "IN"
178
          | "IO"
179
          | "IQ"
180
          | "IR"
181
          | "IS"
182
          | "IT"
183
          | "JE"
184
          | "JM"
185
          | "JO"
186
          | "JP"
187
          | "KE"
188
          | "KG"
189
          | "KH"
190
          | "KI"
191
          | "KM"
192
          | "KN"
193
          | "KP"
194
          | "KR"
195
          | "KW"
196
          | "KY"
197
          | "KZ"
198
          | "LA"
199
          | "LB"
200
          | "LC"
201
          | "LI"
202
          | "LK"
203
          | "LR"
204
          | "LS"
205
          | "LT"
206
          | "LU"
207
          | "LV"
208
          | "LY"
209
          | "MA"
210
          | "MC"
211
          | "MD"
212
          | "ME"
213
          | "MF"
214
          | "MG"
215
          | "MH"
216
          | "MK"
217
          | "ML"
218
          | "MM"
219
          | "MN"
220
          | "MO"
221
          | "MP"
222
          | "MQ"
223
          | "MR"
224
          | "MS"
225
          | "MT"
226
          | "MU"
227
          | "MV"
228
          | "MW"
229
          | "MX"
230
          | "MY"
231
          | "MZ"
232
          | "NA"
233
          | "NC"
234
          | "NE"
235
          | "NF"
236
          | "NG"
237
          | "NI"
238
          | "NL"
239
          | "NO"
240
          | "NP"
241
          | "NR"
242
          | "NU"
243
          | "NZ"
244
          | "OM"
245
          | "PA"
246
          | "PE"
247
          | "PF"
248
          | "PG"
249
          | "PH"
250
          | "PK"
251
          | "PL"
252
          | "PM"
253
          | "PN"
254
          | "PR"
255
          | "PS"
256
          | "PT"
257
          | "PW"
258
          | "PY"
259
          | "QA"
260
          | "RE"
261
          | "RO"
262
          | "RS"
263
          | "RU"
264
          | "RW"
265
          | "SA"
266
          | "SB"
267
          | "SC"
268
          | "SD"
269
          | "SE"
270
          | "SG"
271
          | "SH"
272
          | "SI"
273
          | "SJ"
274
          | "SK"
275
          | "SL"
276
          | "SM"
277
          | "SN"
278
          | "SO"
279
          | "SR"
280
          | "SS"
281
          | "ST"
282
          | "SV"
283
          | "SX"
284
          | "SY"
285
          | "SZ"
286
          | "TC"
287
          | "TD"
288
          | "TF"
289
          | "TG"
290
          | "TH"
291
          | "TJ"
292
          | "TK"
293
          | "TL"
294
          | "TM"
295
          | "TN"
296
          | "TO"
297
          | "TR"
298
          | "TT"
299
          | "TV"
300
          | "TW"
301
          | "TZ"
302
          | "UA"
303
          | "UG"
304
          | "UM"
305
          | "US"
306
          | "UY"
307
          | "UZ"
308
          | "VA"
309
          | "VC"
310
          | "VE"
311
          | "VG"
312
          | "VI"
313
          | "VN"
314
          | "VU"
315
          | "WF"
316
          | "WS"
317
          | "YE"
318
          | "YT"
319
          | "ZA"
320
          | "ZM"
321
          | "ZW";
322
        first_name?: string;
323
        last_name?: string;
324
      };
325
    };
326
  },
327
) {
328
  const url = new URL(`https://connect.squareup.com/v2/bookings/${booking_id}`);
329

330
  const response = await fetch(url, {
331
    method: "PUT",
332
    headers: {
333
      "Content-Type": "application/json",
334
      Authorization: "Bearer " + auth.token,
335
    },
336
    body: JSON.stringify(body),
337
  });
338
  if (!response.ok) {
339
    const text = await response.text();
340
    throw new Error(`${response.status} ${text}`);
341
  }
342
  return await response.json();
343
}
344