1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Email an invoice |
7 | * Email an invoice 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 | invoice_id: string, |
12 | organization_id: string | undefined, |
13 | send_customer_statement: string | undefined, |
14 | send_attachment: string | undefined, |
15 | attachments: string | undefined, |
16 | body: { |
17 | send_from_org_email_id?: false | true; |
18 | to_mail_ids: string[]; |
19 | cc_mail_ids?: string[]; |
20 | subject?: string; |
21 | body?: string; |
22 | }, |
23 | ) { |
24 | const url = new URL( |
25 | `https://www.zohoapis.com/inventory/v1/invoices/${invoice_id}/email`, |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["organization_id", organization_id], |
29 | ["send_customer_statement", send_customer_statement], |
30 | ["send_attachment", send_attachment], |
31 | ["attachments", attachments], |
32 | ]) { |
33 | if (v !== undefined && v !== "" && k !== undefined) { |
34 | url.searchParams.append(k, v); |
35 | } |
36 | } |
37 | const response = await fetch(url, { |
38 | method: "POST", |
39 | headers: { |
40 | "Content-Type": "application/json", |
41 | Authorization: "Zoho-oauthtoken " + auth.token, |
42 | }, |
43 | body: JSON.stringify(body), |
44 | }); |
45 | if (!response.ok) { |
46 | const text = await response.text(); |
47 | throw new Error(`${response.status} ${text}`); |
48 | } |
49 | return await response.json(); |
50 | } |
51 |
|