1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create an organization |
7 | * Create an organization. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | name: string; |
14 | fiscal_year_start_month?: string; |
15 | currency_code: string; |
16 | time_zone: string; |
17 | date_format?: string; |
18 | field_separator?: string; |
19 | language_code?: string; |
20 | industry_type?: string; |
21 | industry_size?: string; |
22 | portal_name: string; |
23 | org_address?: string; |
24 | remit_to_address?: string; |
25 | address?: { |
26 | street_address1?: string; |
27 | street_address2?: string; |
28 | city?: string; |
29 | state?: string; |
30 | country?: string; |
31 | zip?: string; |
32 | }[]; |
33 | }, |
34 | ) { |
35 | const url = new URL(`https://www.zohoapis.com/inventory/v1/organizations`); |
36 | for (const [k, v] of [["organization_id", organization_id]]) { |
37 | if (v !== undefined && v !== "" && k !== undefined) { |
38 | url.searchParams.append(k, v); |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "POST", |
43 | headers: { |
44 | "Content-Type": "application/json", |
45 | Authorization: "Zoho-oauthtoken " + auth.token, |
46 | }, |
47 | body: JSON.stringify(body), |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|