1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List of transactions for an account |
7 | * List all involved transactions for the given account. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | account_id: string | undefined, |
13 | date: string | undefined, |
14 | amount: string | undefined, |
15 | filter_by: string | undefined, |
16 | transaction_type: string | undefined, |
17 | sort_column: string | undefined, |
18 | ) { |
19 | const url = new URL( |
20 | `https://www.zohoapis.com/books/v3/chartofaccounts/transactions`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["organization_id", organization_id], |
24 | ["account_id", account_id], |
25 | ["date", date], |
26 | ["amount", amount], |
27 | ["filter_by", filter_by], |
28 | ["transaction_type", transaction_type], |
29 | ["sort_column", sort_column], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Zoho-oauthtoken " + auth.token, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|