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