1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List All Composite Items |
7 | * List of all composite items. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | page: string | undefined, |
13 | per_page: string | undefined, |
14 | sort_column: string | undefined, |
15 | sort_order: string | undefined, |
16 | filter_by: string | undefined, |
17 | usestate: string | undefined, |
18 | response_option: string | undefined, |
19 | ) { |
20 | const url = new URL(`https://www.zohoapis.com/inventory/v1/compositeitems`); |
21 | for (const [k, v] of [ |
22 | ["organization_id", organization_id], |
23 | ["page", page], |
24 | ["per_page", per_page], |
25 | ["sort_column", sort_column], |
26 | ["sort_order", sort_order], |
27 | ["filter_by", filter_by], |
28 | ["usestate", usestate], |
29 | ["response_option", response_option], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Zoho-oauthtoken " + auth.token, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|