Edits history of script submission #11691 for ' Export all webhook events (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Export all webhook events
     * This endpoint will submit a request to get the history of webhooks in the CSV file. The link to download the CSV file will be sent to the webhook that was provided in the notifyURL.
     */
    export async function main(
      auth: Brevo,
      body: {
        days?: number;
        startDate?: string;
        endDate?: string;
        sort?: string;
        type: "transactional" | "marketing";
        event:
          | "invalid_parameter"
          | "missing_parameter"
          | "hardBounce"
          | "softBounce"
          | "delivered"
          | "spam"
          | "request"
          | "opened"
          | "click"
          | "invalid"
          | "deferred"
          | "blocked"
          | "unsubscribed"
          | "error"
          | "uniqueOpened"
          | "loadedByProxy"
          | "allEvents";
        notifyURL: string;
        webhookId?: number;
        email?: string;
        messageId?: number;
      },
    ) {
      const url = new URL(`https://api.brevo.com/v3/webhooks/export`);
    
      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