1 | |
2 | type Zoho = { |
3 | token: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Publish API 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 | privatelink: string | undefined, |
16 | from: string | undefined, |
17 | limit: string | undefined, |
18 | criteria: string | undefined, |
19 | field_config: string | undefined, |
20 | fields: string | undefined, |
21 | max_records: string | undefined, |
22 | record_cursor?: string, |
23 | ) { |
24 | const url = new URL( |
25 | `${auth.baseUrl}/creator/v2.1/publish/${account_owner_name}/${app_link_name}/report/${report_link_name}`, |
26 | ); |
27 | for (const [k, v] of [ |
28 | ["privatelink", privatelink], |
29 | ["from", from], |
30 | ["limit", limit], |
31 | ["criteria", criteria], |
32 | ["field_config", field_config], |
33 | ["fields", fields], |
34 | ["max_records", max_records], |
35 | ]) { |
36 | if (v !== undefined && v !== "" && k !== undefined) { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "GET", |
42 | headers: { |
43 | ...(record_cursor ? { record_cursor: record_cursor } : {}), |
44 | Authorization: "Zoho-oauthtoken " + auth.token, |
45 | }, |
46 | body: undefined, |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|