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