0

UpdateCustomer

by
Published Oct 17, 2025

Updates a customer profile. This endpoint supports sparse updates, so only new or changed fields are required in the request. To add or update a field, specify the new value. To remove a field, specify `null`. To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile. You cannot use this endpoint to change cards on file. To make changes, use the [Cards API]($e/Cards) or [Gift Cards API]($e/GiftCards).

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * UpdateCustomer
7
 * Updates a customer profile. This endpoint supports sparse updates, so only new or changed fields are required in the request.
8
To add or update a field, specify the new value. To remove a field, specify `null`.
9

10
To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile.
11

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

301
  const response = await fetch(url, {
302
    method: "PUT",
303
    headers: {
304
      "Content-Type": "application/json",
305
      Authorization: "Bearer " + auth.token,
306
    },
307
    body: JSON.stringify(body),
308
  });
309
  if (!response.ok) {
310
    const text = await response.text();
311
    throw new Error(`${response.status} ${text}`);
312
  }
313
  return await response.json();
314
}
315