1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update comment |
7 | * Update an existing comment of an invoice. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | invoice_id: string, |
12 | comment_id: string, |
13 | organization_id: string | undefined, |
14 | description: string | undefined, |
15 | show_comment_to_clients: string | undefined, |
16 | ) { |
17 | const url = new URL( |
18 | `https://www.zohoapis.com/inventory/v1/invoices/${invoice_id}/comments/${comment_id}`, |
19 | ); |
20 | for (const [k, v] of [ |
21 | ["organization_id", organization_id], |
22 | ["description", description], |
23 | ["show_comment_to_clients", show_comment_to_clients], |
24 | ]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "PUT", |
31 | headers: { |
32 | Authorization: "Zoho-oauthtoken " + auth.token, |
33 | }, |
34 | body: undefined, |
35 | }); |
36 | if (!response.ok) { |
37 | const text = await response.text(); |
38 | throw new Error(`${response.status} ${text}`); |
39 | } |
40 | return await response.json(); |
41 | } |
42 |
|