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