1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | module_api_name: string, |
12 | approved: string | undefined, |
13 | converted: string | undefined, |
14 | cvid: string | undefined, |
15 | ids: string | undefined, |
16 | uid: string | undefined, |
17 | fields: string | undefined, |
18 | sort_by: string | undefined, |
19 | sort_order: string | undefined, |
20 | page: string | undefined, |
21 | per_page: string | undefined, |
22 | startDateTime: string | undefined, |
23 | endDateTime: string | undefined, |
24 | territory_id: string | undefined, |
25 | include_child: string | undefined, |
26 | page_token: string | undefined, |
27 | If_Modified_Since?: string, |
28 | X_EXTERNAL?: string, |
29 | ) { |
30 | const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}`); |
31 | for (const [k, v] of [ |
32 | ["approved", approved], |
33 | ["converted", converted], |
34 | ["cvid", cvid], |
35 | ["ids", ids], |
36 | ["uid", uid], |
37 | ["fields", fields], |
38 | ["sort_by", sort_by], |
39 | ["sort_order", sort_order], |
40 | ["page", page], |
41 | ["per_page", per_page], |
42 | ["startDateTime", startDateTime], |
43 | ["endDateTime", endDateTime], |
44 | ["territory_id", territory_id], |
45 | ["include_child", include_child], |
46 | ["page_token", page_token], |
47 | ]) { |
48 | if (v !== undefined && v !== "" && k !== undefined) { |
49 | url.searchParams.append(k, v); |
50 | } |
51 | } |
52 | const response = await fetch(url, { |
53 | method: "GET", |
54 | headers: { |
55 | ...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}), |
56 | ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}), |
57 | Authorization: "Zoho-oauthtoken " + auth.token, |
58 | }, |
59 | body: undefined, |
60 | }); |
61 | if (!response.ok) { |
62 | const text = await response.text(); |
63 | throw new Error(`${response.status} ${text}`); |
64 | } |
65 | return await response.json(); |
66 | } |
67 |
|