Edits history of script submission #21625 for ' Get related record using external id (zoho)'

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