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