1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create company |
7 | * Creates a new company. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | body: { |
12 | name: string; |
13 | externalId?: string; |
14 | avatarUrl?: string; |
15 | emails?: { |
16 | type?: "home" | "work" | "other"; |
17 | email: string; |
18 | verified?: false | true; |
19 | }[]; |
20 | phones?: { |
21 | type?: "home" | "work" | "other" | "mobile" | "fax"; |
22 | phone: string; |
23 | verified?: false | true; |
24 | }[]; |
25 | whatsapps?: { type?: "mobile"; phone: string; verified?: false | true }[]; |
26 | socials?: { |
27 | type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest"; |
28 | userid?: string; |
29 | username: string; |
30 | url?: string; |
31 | verified?: false | true; |
32 | }[]; |
33 | urls?: { type?: "other" | "website" | "blog"; url: string }[]; |
34 | domains?: { domain: string }[]; |
35 | locations?: { |
36 | type?: "home" | "work" | "other"; |
37 | name?: string; |
38 | address?: string; |
39 | address2?: string; |
40 | address3?: string; |
41 | latitude?: number; |
42 | longitude?: number; |
43 | countryCode?: string; |
44 | countryName?: string; |
45 | regionCode?: string; |
46 | regionName?: string; |
47 | cityName?: string; |
48 | zipCode?: string; |
49 | areaCode?: string; |
50 | }[]; |
51 | employeeCount?: number; |
52 | tags?: string[]; |
53 | createdAt?: string; |
54 | importedAt?: string; |
55 | rev?: number; |
56 | custom?: {}; |
57 | defaultLang?: string; |
58 | }, |
59 | ) { |
60 | const url = new URL(`https://api.kustomerapp.com/v1/companies`); |
61 |
|
62 | const response = await fetch(url, { |
63 | method: "POST", |
64 | headers: { |
65 | "Content-Type": "application/json", |
66 | Authorization: "Bearer " + auth.apiKey, |
67 | }, |
68 | body: JSON.stringify(body), |
69 | }); |
70 | if (!response.ok) { |
71 | const text = await response.text(); |
72 | throw new Error(`${response.status} ${text}`); |
73 | } |
74 | return await response.json(); |
75 | } |
76 |
|