0

UpdateVendor

by
Published Oct 17, 2025

Updates an existing [Vendor]($m/Vendor) object as a supplier to a seller.

Script square Verified

The script

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

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