1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Email a sales order |
7 | * Email a sales order to the customer. Input json string is not mandatory. If input json string is empty, mail will be send with default mail content. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | salesorder_id: string, |
12 | organization_id: string | undefined, |
13 | attachments: string | undefined, |
14 | send_attachment: string | undefined, |
15 | file_name: string | undefined, |
16 | body: { |
17 | from_address_id?: string; |
18 | send_from_org_email_id?: false | true; |
19 | to_mail_ids: string[]; |
20 | cc_mail_ids?: string[]; |
21 | bcc_mail_ids?: string[]; |
22 | subject: string; |
23 | documents?: string; |
24 | invoice_id?: string; |
25 | body: string; |
26 | }, |
27 | ) { |
28 | const url = new URL( |
29 | `https://www.zohoapis.com/books/v3/salesorders/${salesorder_id}/email`, |
30 | ); |
31 | for (const [k, v] of [ |
32 | ["organization_id", organization_id], |
33 | ["attachments", attachments], |
34 | ["send_attachment", send_attachment], |
35 | ["file_name", file_name], |
36 | ]) { |
37 | if (v !== undefined && v !== "" && k !== undefined) { |
38 | url.searchParams.append(k, v); |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "POST", |
43 | headers: { |
44 | "Content-Type": "application/json", |
45 | Authorization: "Zoho-oauthtoken " + auth.token, |
46 | }, |
47 | body: JSON.stringify(body), |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|