Edits history of script submission #21618 for ' Get records (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Get records
     *
     */
    export async function main(
      auth: Zoho,
      module_api_name: string,
      approved: string | undefined,
      converted: string | undefined,
      cvid: string | undefined,
      ids: string | undefined,
      uid: string | undefined,
      fields: string | undefined,
      sort_by: string | undefined,
      sort_order: string | undefined,
      page: string | undefined,
      per_page: string | undefined,
      startDateTime: string | undefined,
      endDateTime: string | undefined,
      territory_id: string | undefined,
      include_child: string | undefined,
      page_token: string | undefined,
      If_Modified_Since?: string,
      X_EXTERNAL?: string,
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}`);
      for (const [k, v] of [
        ["approved", approved],
        ["converted", converted],
        ["cvid", cvid],
        ["ids", ids],
        ["uid", uid],
        ["fields", fields],
        ["sort_by", sort_by],
        ["sort_order", sort_order],
        ["page", page],
        ["per_page", per_page],
        ["startDateTime", startDateTime],
        ["endDateTime", endDateTime],
        ["territory_id", territory_id],
        ["include_child", include_child],
        ["page_token", page_token],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          ...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}),
          ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}),
          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