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