Edits history of script submission #21611 for ' Get record (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Get record
     *
     */
    export async function main(
      auth: Zoho,
      module_api_name: string,
      id: string,
      approved: string | undefined,
      converted: string | undefined,
      cvid: string | undefined,
      uid: string | undefined,
      fields: string | undefined,
      startDateTime: string | undefined,
      endDateTime: string | undefined,
      territory_id: string | undefined,
      include_child: string | undefined,
      on_demand_properties: string | undefined,
      If_Modified_Since?: string,
      X_EXTERNAL?: string,
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}/${id}`);
      for (const [k, v] of [
        ["approved", approved],
        ["converted", converted],
        ["cvid", cvid],
        ["uid", uid],
        ["fields", fields],
        ["startDateTime", startDateTime],
        ["endDateTime", endDateTime],
        ["territory_id", territory_id],
        ["include_child", include_child],
        ["on_demand_properties", on_demand_properties],
      ]) {
        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