Edits history of script submission #11718 for ' Get all deals (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Get all deals
     *
     */
    export async function main(
      auth: Brevo,
      filters_attributes_deal_name_: string | undefined,
      filters_linkedCompaniesIds_: string | undefined,
      filters_linkedContactsIds_: string | undefined,
      modifiedSince: string | undefined,
      createdSince: string | undefined,
      offset: string | undefined,
      limit: string | undefined,
      sort: "asc" | "desc" | undefined,
    ) {
      const url = new URL(`https://api.brevo.com/v3/crm/deals`);
      for (const [k, v] of [
        ["filters[attributes.deal_name]", filters_attributes_deal_name_],
        ["filters[linkedCompaniesIds]", filters_linkedCompaniesIds_],
        ["filters[linkedContactsIds]", filters_linkedContactsIds_],
        ["modifiedSince", modifiedSince],
        ["createdSince", createdSince],
        ["offset", offset],
        ["limit", limit],
        ["sort", sort],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "api-key": auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago