1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Get timelines |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | record_id: string, |
12 | _module: string, |
13 | include_inner_details: |
14 | | "field_history.data_type" |
15 | | "field_history.enable_colour_code" |
16 | | "field_history.field_label" |
17 | | "field_history.pick_list_values" |
18 | | undefined, |
19 | sort_by: string | undefined, |
20 | sort_order: "asc" | "desc" | undefined, |
21 | include_timeline_type: string | undefined, |
22 | include: "extension" | "type" | undefined, |
23 | filters: string | undefined, |
24 | per_page: string | undefined, |
25 | page: string | undefined, |
26 | page_token: string | undefined, |
27 | ) { |
28 | const url = new URL( |
29 | `https://zohoapis.com/crm/v8/${_module}/${record_id}/__timeline`, |
30 | ); |
31 | for (const [k, v] of [ |
32 | ["include_inner_details", include_inner_details], |
33 | ["sort_by", sort_by], |
34 | ["sort_order", sort_order], |
35 | ["include_timeline_type", include_timeline_type], |
36 | ["include", include], |
37 | ["filters", filters], |
38 | ["per_page", per_page], |
39 | ["page", page], |
40 | ["page_token", page_token], |
41 | ]) { |
42 | if (v !== undefined && v !== "" && k !== undefined) { |
43 | url.searchParams.append(k, v); |
44 | } |
45 | } |
46 | const response = await fetch(url, { |
47 | method: "GET", |
48 | headers: { |
49 | Authorization: "Zoho-oauthtoken " + auth.token, |
50 | }, |
51 | body: undefined, |
52 | }); |
53 | if (!response.ok) { |
54 | const text = await response.text(); |
55 | throw new Error(`${response.status} ${text}`); |
56 | } |
57 | return await response.json(); |
58 | } |
59 |
|