1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List vendor payments |
7 | * List all the payments made to your vendor. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | vendor_name: string | undefined, |
13 | reference_number: string | undefined, |
14 | payment_number: string | undefined, |
15 | date: string | undefined, |
16 | amount: string | undefined, |
17 | payment_mode: string | undefined, |
18 | notes: string | undefined, |
19 | vendor_id: string | undefined, |
20 | last_modified_time: string | undefined, |
21 | bill_id: string | undefined, |
22 | description: string | undefined, |
23 | filter_by: string | undefined, |
24 | search_text: string | undefined, |
25 | sort_column: string | undefined, |
26 | ) { |
27 | const url = new URL(`https://www.zohoapis.com/books/v3/vendorpayments`); |
28 | for (const [k, v] of [ |
29 | ["organization_id", organization_id], |
30 | ["vendor_name", vendor_name], |
31 | ["reference_number", reference_number], |
32 | ["payment_number", payment_number], |
33 | ["date", date], |
34 | ["amount", amount], |
35 | ["payment_mode", payment_mode], |
36 | ["notes", notes], |
37 | ["vendor_id", vendor_id], |
38 | ["last_modified_time", last_modified_time], |
39 | ["bill_id", bill_id], |
40 | ["description", description], |
41 | ["filter_by", filter_by], |
42 | ["search_text", search_text], |
43 | ["sort_column", sort_column], |
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 |
|