1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List Expenses |
7 | * List all the Expenses with pagination. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | description: string | undefined, |
13 | reference_number: string | undefined, |
14 | date: string | undefined, |
15 | status: string | undefined, |
16 | amount: string | undefined, |
17 | account_name: string | undefined, |
18 | customer_name: string | undefined, |
19 | vendor_name: string | undefined, |
20 | customer_id: string | undefined, |
21 | vendor_id: string | undefined, |
22 | recurring_expense_id: string | undefined, |
23 | paid_through_account_id: string | undefined, |
24 | search_text: string | undefined, |
25 | sort_column: string | undefined, |
26 | filter_by: string | undefined, |
27 | ) { |
28 | const url = new URL(`https://www.zohoapis.com/books/v3/expenses`); |
29 | for (const [k, v] of [ |
30 | ["organization_id", organization_id], |
31 | ["description", description], |
32 | ["reference_number", reference_number], |
33 | ["date", date], |
34 | ["status", status], |
35 | ["amount", amount], |
36 | ["account_name", account_name], |
37 | ["customer_name", customer_name], |
38 | ["vendor_name", vendor_name], |
39 | ["customer_id", customer_id], |
40 | ["vendor_id", vendor_id], |
41 | ["recurring_expense_id", recurring_expense_id], |
42 | ["paid_through_account_id", paid_through_account_id], |
43 | ["search_text", search_text], |
44 | ["sort_column", sort_column], |
45 | ["filter_by", filter_by], |
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 |
|