0

Create an external feed

by
Published Apr 8, 2025

This endpoint will create an external feed.

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Create an external feed
7
 * This endpoint will create an external feed.
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    name: string;
13
    url: string;
14
    authType?: "basic" | "token" | "noAuth";
15
    username?: string;
16
    password?: string;
17
    token?: string;
18
    headers?: { name?: string; value?: string }[];
19
    maxRetries?: number;
20
    cache?: false | true;
21
  },
22
) {
23
  const url = new URL(`https://api.brevo.com/v3/feeds`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      "api-key": auth.apiKey,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39