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