1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Bulk batch update customers |
7 | * Updates a bulk batch of customers. |
8 |
|
9 | Use the `ids` query param to update multiple customers in bulk with the same data. |
10 |
|
11 | Any one of the following roles is required for this endpoint: |
12 |
|
13 | |Legacy Role|Equivalent Permission Set Role| |
14 | |-----|--------| |
15 | |org.user.customer.write|org.permission.customer.update| |
16 | */ |
17 | export async function main( |
18 | auth: Kustomer, |
19 | ids: string | undefined, |
20 | body: { |
21 | id: string; |
22 | name?: string; |
23 | company?: string; |
24 | externalId?: string; |
25 | username?: string; |
26 | signedUpAt?: string; |
27 | lastActivityAt?: string; |
28 | lastCustomerActivityAt?: string; |
29 | lastSeenAt?: string; |
30 | avatarUrl?: string; |
31 | externalIds?: { externalId: string; verified?: false | true }[]; |
32 | sharedExternalIds?: { externalId: string; verified?: false | true }[]; |
33 | emails?: { |
34 | type?: "home" | "work" | "other"; |
35 | email: string; |
36 | verified?: false | true; |
37 | }[]; |
38 | sharedEmails?: { |
39 | type?: "home" | "work" | "other"; |
40 | email: string; |
41 | verified?: false | true; |
42 | }[]; |
43 | phones?: { |
44 | type?: "home" | "work" | "other" | "mobile" | "fax"; |
45 | phone: string; |
46 | verified?: false | true; |
47 | }[]; |
48 | sharedPhones?: { |
49 | type?: "home" | "work" | "other" | "mobile" | "fax"; |
50 | phone: string; |
51 | verified?: false | true; |
52 | }[]; |
53 | facebookIds?: { pageId: string; userId: string; name?: string }[]; |
54 | socials?: { |
55 | type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest"; |
56 | userid?: string; |
57 | username: string; |
58 | url?: string; |
59 | verified?: false | true; |
60 | }[]; |
61 | sharedSocials?: { |
62 | type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest"; |
63 | userid?: string; |
64 | username: string; |
65 | url?: string; |
66 | verified?: false | true; |
67 | }[]; |
68 | urls?: { type?: "other" | "website" | "blog"; url: string }[]; |
69 | locations?: { |
70 | type?: "home" | "work" | "other"; |
71 | name?: string; |
72 | address?: string; |
73 | address2?: string; |
74 | address3?: string; |
75 | latitude?: number; |
76 | longitude?: number; |
77 | countryCode?: string; |
78 | countryName?: string; |
79 | regionCode?: string; |
80 | regionName?: string; |
81 | cityName?: string; |
82 | zipCode?: string; |
83 | areaCode?: string; |
84 | }[]; |
85 | locale?: string; |
86 | timeZone?: string; |
87 | tags?: string[]; |
88 | sentiment?: { polarity: 0 | 1 | -1; confidence: number }; |
89 | custom?: {}; |
90 | birthdayAt?: string; |
91 | gender?: "m" | "f"; |
92 | createdAt?: string; |
93 | importedAt?: string; |
94 | rev?: number; |
95 | defaultLang?: string; |
96 | }[], |
97 | ) { |
98 | const url = new URL(`https://api.kustomerapp.com/v1/customers/bulk`); |
99 | for (const [k, v] of [["ids", ids]]) { |
100 | if (v !== undefined && v !== "" && k !== undefined) { |
101 | url.searchParams.append(k, v); |
102 | } |
103 | } |
104 | const response = await fetch(url, { |
105 | method: "PUT", |
106 | headers: { |
107 | "Content-Type": "application/json", |
108 | Authorization: "Bearer " + auth.apiKey, |
109 | }, |
110 | body: JSON.stringify(body), |
111 | }); |
112 | if (!response.ok) { |
113 | const text = await response.text(); |
114 | throw new Error(`${response.status} ${text}`); |
115 | } |
116 | return await response.json(); |
117 | } |
118 |
|