1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List items |
7 | * Get the list of all active items with pagination. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | name: string | undefined, |
13 | description: string | undefined, |
14 | rate: string | undefined, |
15 | tax_id: string | undefined, |
16 | tax_name: string | undefined, |
17 | is_taxable: string | undefined, |
18 | tax_exemption_id: string | undefined, |
19 | account_id: string | undefined, |
20 | filter_by: string | undefined, |
21 | search_text: string | undefined, |
22 | sort_column: string | undefined, |
23 | sat_item_key_code: string | undefined, |
24 | unitkey_code: string | undefined, |
25 | ) { |
26 | const url = new URL(`https://www.zohoapis.com/books/v3/items`); |
27 | for (const [k, v] of [ |
28 | ["organization_id", organization_id], |
29 | ["name", name], |
30 | ["description", description], |
31 | ["rate", rate], |
32 | ["tax_id", tax_id], |
33 | ["tax_name", tax_name], |
34 | ["is_taxable", is_taxable], |
35 | ["tax_exemption_id", tax_exemption_id], |
36 | ["account_id", account_id], |
37 | ["filter_by", filter_by], |
38 | ["search_text", search_text], |
39 | ["sort_column", sort_column], |
40 | ["sat_item_key_code", sat_item_key_code], |
41 | ["unitkey_code", unitkey_code], |
42 | ]) { |
43 | if (v !== undefined && v !== "" && k !== undefined) { |
44 | url.searchParams.append(k, v); |
45 | } |
46 | } |
47 | const response = await fetch(url, { |
48 | method: "GET", |
49 | headers: { |
50 | Authorization: "Zoho-oauthtoken " + auth.token, |
51 | }, |
52 | body: undefined, |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|