1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get journal list |
7 | * Get journal list. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | entry_number: string | undefined, |
13 | reference_number: string | undefined, |
14 | date: string | undefined, |
15 | notes: string | undefined, |
16 | last_modified_time: string | undefined, |
17 | total: string | undefined, |
18 | customer_id: string | undefined, |
19 | vendor_id: string | undefined, |
20 | filter_by: string | undefined, |
21 | sort_column: string | undefined, |
22 | ) { |
23 | const url = new URL(`https://www.zohoapis.com/books/v3/journals`); |
24 | for (const [k, v] of [ |
25 | ["organization_id", organization_id], |
26 | ["entry_number", entry_number], |
27 | ["reference_number", reference_number], |
28 | ["date", date], |
29 | ["notes", notes], |
30 | ["last_modified_time", last_modified_time], |
31 | ["total", total], |
32 | ["customer_id", customer_id], |
33 | ["vendor_id", vendor_id], |
34 | ["filter_by", filter_by], |
35 | ["sort_column", sort_column], |
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 |
|