1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List account details for base currency adjustment |
7 | * List of accounts having transaction with effect to the given exchange rate. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | currency_id: string | undefined, |
13 | adjustment_date: string | undefined, |
14 | exchange_rate: string | undefined, |
15 | notes: string | undefined, |
16 | ) { |
17 | const url = new URL( |
18 | `https://www.zohoapis.com/books/v3/basecurrencyadjustment/accounts`, |
19 | ); |
20 | for (const [k, v] of [ |
21 | ["organization_id", organization_id], |
22 | ["currency_id", currency_id], |
23 | ["adjustment_date", adjustment_date], |
24 | ["exchange_rate", exchange_rate], |
25 | ["notes", notes], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Zoho-oauthtoken " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|