1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List all Recurring Invoice |
7 | * List the details of all recurring invoice. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | recurrence_name: string | undefined, |
13 | item_name: string | undefined, |
14 | item_description: string | undefined, |
15 | customer_name: string | undefined, |
16 | line_item_id: string | undefined, |
17 | item_id: string | undefined, |
18 | tax_id: string | undefined, |
19 | notes: string | undefined, |
20 | start_date: string | undefined, |
21 | end_date: string | undefined, |
22 | customer_id: string | undefined, |
23 | status: string | undefined, |
24 | filter_by: string | undefined, |
25 | search_text: string | undefined, |
26 | sort_column: string | undefined, |
27 | ) { |
28 | const url = new URL(`https://www.zohoapis.com/books/v3/recurringinvoices`); |
29 | for (const [k, v] of [ |
30 | ["organization_id", organization_id], |
31 | ["recurrence_name", recurrence_name], |
32 | ["item_name", item_name], |
33 | ["item_description", item_description], |
34 | ["customer_name", customer_name], |
35 | ["line_item_id", line_item_id], |
36 | ["item_id", item_id], |
37 | ["tax_id", tax_id], |
38 | ["notes", notes], |
39 | ["start_date", start_date], |
40 | ["end_date", end_date], |
41 | ["customer_id", customer_id], |
42 | ["status", status], |
43 | ["filter_by", filter_by], |
44 | ["search_text", search_text], |
45 | ["sort_column", sort_column], |
46 | ]) { |
47 | if (v !== undefined && v !== "" && k !== undefined) { |
48 | url.searchParams.append(k, v); |
49 | } |
50 | } |
51 | const response = await fetch(url, { |
52 | method: "GET", |
53 | headers: { |
54 | Authorization: "Zoho-oauthtoken " + auth.token, |
55 | }, |
56 | body: undefined, |
57 | }); |
58 | if (!response.ok) { |
59 | const text = await response.text(); |
60 | throw new Error(`${response.status} ${text}`); |
61 | } |
62 | return await response.json(); |
63 | } |
64 |
|