1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Email an estimate |
7 | * Email an estimate 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 | estimate_id: string, |
12 | organization_id: string | undefined, |
13 | attachments: string | undefined, |
14 | body: { |
15 | send_from_org_email_id?: false | true; |
16 | to_mail_ids: string[]; |
17 | cc_mail_ids?: string[]; |
18 | subject?: string; |
19 | body?: string; |
20 | }, |
21 | ) { |
22 | const url = new URL( |
23 | `https://www.zohoapis.com/books/v3/estimates/${estimate_id}/email`, |
24 | ); |
25 | for (const [k, v] of [ |
26 | ["organization_id", organization_id], |
27 | ["attachments", attachments], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "POST", |
35 | headers: { |
36 | "Content-Type": "application/json", |
37 | Authorization: "Zoho-oauthtoken " + auth.token, |
38 | }, |
39 | body: JSON.stringify(body), |
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 |
|