Edits history of script submission #21395 for ' Delete related records using external id (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Delete related records using external id
     *
     */
    export async function main(
      auth: Zoho,
      module_api_name: string,
      external_value: string,
      related_list_api_name: string,
      ids: string | undefined,
      X_EXTERNAL?: string,
    ) {
      const url = new URL(
        `https://zohoapis.com/crm/v8/${module_api_name}/${external_value}/${related_list_api_name}`,
      );
      for (const [k, v] of [["ids", ids]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          ...(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