1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Add attachment to a sales order |
7 | * Attach a file to a sales order. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | salesorder_id: string, |
12 | organization_id: string | undefined, |
13 | attachment: string | undefined, |
14 | can_send_in_mail: string | undefined, |
15 | doc: string | undefined, |
16 | totalFiles: string | undefined, |
17 | document_ids: string | undefined, |
18 | ) { |
19 | const url = new URL( |
20 | `https://www.zohoapis.com/books/v3/salesorders/${salesorder_id}/attachment`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["organization_id", organization_id], |
24 | ["attachment", attachment], |
25 | ["can_send_in_mail", can_send_in_mail], |
26 | ["doc", doc], |
27 | ["totalFiles", totalFiles], |
28 | ["document_ids", document_ids], |
29 | ]) { |
30 | if (v !== undefined && v !== "" && k !== undefined) { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "POST", |
36 | headers: { |
37 | Authorization: "Zoho-oauthtoken " + auth.token, |
38 | }, |
39 | body: undefined, |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|