Edits history of script submission #21862 for ' Publish API Get Records Quick View (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
      baseUrl: string;
    };
    /**
     * Publish API Get Records Quick View
     * 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.
     */
    export async function main(
      auth: Zoho,
      account_owner_name: string,
      app_link_name: string,
      report_link_name: string,
      privatelink: string | undefined,
      from: string | undefined,
      limit: string | undefined,
      criteria: string | undefined,
      field_config: string | undefined,
      fields: string | undefined,
      max_records: string | undefined,
      record_cursor?: string,
    ) {
      const url = new URL(
        `${auth.baseUrl}/creator/v2.1/publish/${account_owner_name}/${app_link_name}/report/${report_link_name}`,
      );
      for (const [k, v] of [
        ["privatelink", privatelink],
        ["from", from],
        ["limit", limit],
        ["criteria", criteria],
        ["field_config", field_config],
        ["fields", fields],
        ["max_records", max_records],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          ...(record_cursor ? { record_cursor: record_cursor } : {}),
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago