1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update billing address |
7 | * Updates the billing address for this purchase order alone. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | purchaseorder_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | address?: string; |
15 | city?: string; |
16 | state?: string; |
17 | zip?: string; |
18 | country?: string; |
19 | fax?: string; |
20 | attention?: string; |
21 | is_update_customer?: string; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://www.zohoapis.com/books/v3/purchaseorders/${purchaseorder_id}/address/billing`, |
26 | ); |
27 | for (const [k, v] of [["organization_id", organization_id]]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "PUT", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Zoho-oauthtoken " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|