1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List sales orders |
7 | * List all sales orders. |
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 | salesorder_number: string | undefined, |
16 | item_name: string | undefined, |
17 | item_id: string | undefined, |
18 | item_description: string | undefined, |
19 | reference_number: string | undefined, |
20 | customer_name: string | undefined, |
21 | total: string | undefined, |
22 | date: string | undefined, |
23 | shipment_date: string | undefined, |
24 | status: string | undefined, |
25 | customer_id: string | undefined, |
26 | salesperson_id: string | undefined, |
27 | salesorder_ids: string | undefined, |
28 | zcrm_potential_id: string | undefined, |
29 | last_modified_time: string | undefined, |
30 | accept: string | undefined, |
31 | print: string | undefined, |
32 | customview_id: string | undefined, |
33 | ) { |
34 | const url = new URL(`https://www.zohoapis.com/books/v3/salesorders`); |
35 | for (const [k, v] of [ |
36 | ["organization_id", organization_id], |
37 | ["sort_column", sort_column], |
38 | ["search_text", search_text], |
39 | ["filter_by", filter_by], |
40 | ["salesorder_number", salesorder_number], |
41 | ["item_name", item_name], |
42 | ["item_id", item_id], |
43 | ["item_description", item_description], |
44 | ["reference_number", reference_number], |
45 | ["customer_name", customer_name], |
46 | ["total", total], |
47 | ["date", date], |
48 | ["shipment_date", shipment_date], |
49 | ["status", status], |
50 | ["customer_id", customer_id], |
51 | ["salesperson_id", salesperson_id], |
52 | ["salesorder_ids", salesorder_ids], |
53 | ["zcrm_potential_id", zcrm_potential_id], |
54 | ["last_modified_time", last_modified_time], |
55 | ["accept", accept], |
56 | ["print", print], |
57 | ["customview_id", customview_id], |
58 | ]) { |
59 | if (v !== undefined && v !== "" && k !== undefined) { |
60 | url.searchParams.append(k, v); |
61 | } |
62 | } |
63 | const response = await fetch(url, { |
64 | method: "GET", |
65 | headers: { |
66 | Authorization: "Zoho-oauthtoken " + auth.token, |
67 | }, |
68 | body: undefined, |
69 | }); |
70 | if (!response.ok) { |
71 | const text = await response.text(); |
72 | throw new Error(`${response.status} ${text}`); |
73 | } |
74 | return await response.json(); |
75 | } |
76 |
|