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