1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List bills |
7 | * List all bills with pagination. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | bill_number: string | undefined, |
13 | reference_number: string | undefined, |
14 | date: string | undefined, |
15 | status: string | undefined, |
16 | description: string | undefined, |
17 | vendor_name: string | undefined, |
18 | total: string | undefined, |
19 | vendor_id: string | undefined, |
20 | item_id: string | undefined, |
21 | recurring_bill_id: string | undefined, |
22 | purchaseorder_id: string | undefined, |
23 | last_modified_time: string | undefined, |
24 | filter_by: string | undefined, |
25 | search_text: string | undefined, |
26 | page: string | undefined, |
27 | sort_column: string | undefined, |
28 | sort_order: string | undefined, |
29 | ) { |
30 | const url = new URL(`https://www.zohoapis.com/books/v3/bills`); |
31 | for (const [k, v] of [ |
32 | ["organization_id", organization_id], |
33 | ["bill_number", bill_number], |
34 | ["reference_number", reference_number], |
35 | ["date", date], |
36 | ["status", status], |
37 | ["description", description], |
38 | ["vendor_name", vendor_name], |
39 | ["total", total], |
40 | ["vendor_id", vendor_id], |
41 | ["item_id", item_id], |
42 | ["recurring_bill_id", recurring_bill_id], |
43 | ["purchaseorder_id", purchaseorder_id], |
44 | ["last_modified_time", last_modified_time], |
45 | ["filter_by", filter_by], |
46 | ["search_text", search_text], |
47 | ["page", page], |
48 | ["sort_column", sort_column], |
49 | ["sort_order", sort_order], |
50 | ]) { |
51 | if (v !== undefined && v !== "" && k !== undefined) { |
52 | url.searchParams.append(k, v); |
53 | } |
54 | } |
55 | const response = await fetch(url, { |
56 | method: "GET", |
57 | headers: { |
58 | Authorization: "Zoho-oauthtoken " + auth.token, |
59 | }, |
60 | body: undefined, |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.json(); |
67 | } |
68 |
|