1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List all packages |
7 | * List all existing packages. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | sort_column: string | undefined, |
13 | search_text: string | undefined, |
14 | filter_by: string | undefined, |
15 | packing_number_startswith: string | undefined, |
16 | packing_number_contains: string | undefined, |
17 | salesorder_number_startswith: string | undefined, |
18 | salesorder_number_contains: string | undefined, |
19 | date_start: string | undefined, |
20 | date_end: string | undefined, |
21 | shipment_date_start: string | undefined, |
22 | shipment_date_end: string | undefined, |
23 | customer_name_startswith: string | undefined, |
24 | customer_name_contains: string | undefined, |
25 | delivery_method_startswith: string | undefined, |
26 | delivery_method_contains: string | undefined, |
27 | status: string | undefined, |
28 | customer_id: string | undefined, |
29 | ) { |
30 | const url = new URL(`https://www.zohoapis.com/inventory/v1/packages`); |
31 | for (const [k, v] of [ |
32 | ["organization_id", organization_id], |
33 | ["sort_column", sort_column], |
34 | ["search_text", search_text], |
35 | ["filter_by", filter_by], |
36 | ["packing_number_startswith", packing_number_startswith], |
37 | ["packing_number_contains", packing_number_contains], |
38 | ["salesorder_number_startswith", salesorder_number_startswith], |
39 | ["salesorder_number_contains", salesorder_number_contains], |
40 | ["date_start", date_start], |
41 | ["date_end", date_end], |
42 | ["shipment_date_start", shipment_date_start], |
43 | ["shipment_date_end", shipment_date_end], |
44 | ["customer_name_startswith", customer_name_startswith], |
45 | ["customer_name_contains", customer_name_contains], |
46 | ["delivery_method_startswith", delivery_method_startswith], |
47 | ["delivery_method_contains", delivery_method_contains], |
48 | ["status", status], |
49 | ["customer_id", customer_id], |
50 | ]) { |
51 | if (v !== undefined && v !== "" && k !== undefined) { |
52 | url.searchParams.append(k, v); |
53 | } |
54 | } |
55 | const response = await fetch(url, { |
56 | method: "GET", |
57 | headers: { |
58 | Authorization: "Zoho-oauthtoken " + auth.token, |
59 | }, |
60 | body: undefined, |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.json(); |
67 | } |
68 |
|