0

SearchCustomers

by
Published Oct 17, 2025

Searches the customer profiles associated with a Square account using one or more supported query filters.

Script square Verified

The script

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

323
  const response = await fetch(url, {
324
    method: "POST",
325
    headers: {
326
      "Content-Type": "application/json",
327
      Authorization: "Bearer " + auth.token,
328
    },
329
    body: JSON.stringify(body),
330
  });
331
  if (!response.ok) {
332
    const text = await response.text();
333
    throw new Error(`${response.status} ${text}`);
334
  }
335
  return await response.json();
336
}
337