1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Record count |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | module_api_name: string, |
12 | cvid: string | undefined, |
13 | criteria: string | undefined, |
14 | email: string | undefined, |
15 | phone: string | undefined, |
16 | word: string | undefined, |
17 | ) { |
18 | const url = new URL( |
19 | `https://zohoapis.com/crm/v8/${module_api_name}/actions/count`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["cvid", cvid], |
23 | ["criteria", criteria], |
24 | ["email", email], |
25 | ["phone", phone], |
26 | ["word", word], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "GET", |
34 | headers: { |
35 | Authorization: "Zoho-oauthtoken " + auth.token, |
36 | }, |
37 | body: undefined, |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|