1 | |
2 | type Zoho = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Get Records Quick View |
8 | * This API fetches the records displayed by a report of a Zoho Creator application. Its response will contain the data from the fields displayed in the report's quick view. A maximum of 200 records can be fetched per request. |
9 | */ |
10 | export async function main( |
11 | auth: Zoho, |
12 | account_owner_name: string, |
13 | app_link_name: string, |
14 | report_link_name: string, |
15 | from: string | undefined, |
16 | limit: string | undefined, |
17 | criteria: string | undefined, |
18 | field_config: string | undefined, |
19 | fields: string | undefined, |
20 | max_records: string | undefined, |
21 | record_cursor?: string, |
22 | ) { |
23 | const url = new URL( |
24 | `${auth.baseUrl}/creator/v2.1/data/${account_owner_name}/${app_link_name}/report/${report_link_name}`, |
25 | ); |
26 | for (const [k, v] of [ |
27 | ["from", from], |
28 | ["limit", limit], |
29 | ["criteria", criteria], |
30 | ["field_config", field_config], |
31 | ["fields", fields], |
32 | ["max_records", max_records], |
33 | ]) { |
34 | if (v !== undefined && v !== "" && k !== undefined) { |
35 | url.searchParams.append(k, v); |
36 | } |
37 | } |
38 | const response = await fetch(url, { |
39 | method: "GET", |
40 | headers: { |
41 | ...(record_cursor ? { record_cursor: record_cursor } : {}), |
42 | Authorization: "Zoho-oauthtoken " + auth.token, |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|