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