Edits history of script submission #11632 for ' Create an email campaign (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Create an email campaign
     *
     */
    export async function main(
      auth: Brevo,
      body: {
        tag?: string;
        sender: { name?: string; email?: string; id?: number };
        name: string;
        htmlContent?: string;
        htmlUrl?: string;
        templateId?: number;
        scheduledAt?: string;
        subject?: string;
        previewText?: string;
        replyTo?: string;
        toField?: string;
        recipients?: {
          exclusionListIds?: number[];
          listIds?: number[];
          segmentIds?: number[];
        };
        attachmentUrl?: string;
        inlineImageActivation?: false | true;
        mirrorActive?: false | true;
        footer?: string;
        header?: string;
        utmCampaign?: string;
        params?: {};
        sendAtBestTime?: false | true;
        abTesting?: false | true;
        subjectA?: string;
        subjectB?: string;
        splitRule?: number;
        winnerCriteria?: "open" | "click";
        winnerDelay?: number;
        ipWarmupEnable?: false | true;
        initialQuota?: number;
        increaseRate?: number;
        unsubscriptionPageId?: string;
        updateFormId?: string;
        emailExpirationDate?: {
          duration?: number;
          unit?: "days" | "weeks" | "months";
        };
      },
    ) {
      const url = new URL(`https://api.brevo.com/v3/emailCampaigns`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "api-key": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago