1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List view of accounts |
7 | * List all bank and credit card accounts for your organization. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | filter_by: string | undefined, |
13 | sort_column: string | undefined, |
14 | ) { |
15 | const url = new URL(`https://www.zohoapis.com/books/v3/bankaccounts`); |
16 | for (const [k, v] of [ |
17 | ["organization_id", organization_id], |
18 | ["filter_by", filter_by], |
19 | ["sort_column", sort_column], |
20 | ]) { |
21 | if (v !== undefined && v !== "" && k !== undefined) { |
22 | url.searchParams.append(k, v); |
23 | } |
24 | } |
25 | const response = await fetch(url, { |
26 | method: "GET", |
27 | headers: { |
28 | Authorization: "Zoho-oauthtoken " + auth.token, |
29 | }, |
30 | body: undefined, |
31 | }); |
32 | if (!response.ok) { |
33 | const text = await response.text(); |
34 | throw new Error(`${response.status} ${text}`); |
35 | } |
36 | return await response.json(); |
37 | } |
38 |
|