0

Create an email template

by
Published Apr 8, 2025
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 email template
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    tag?: string;
13
    sender: { name?: string; email?: string; id?: number };
14
    templateName: string;
15
    htmlContent?: string;
16
    htmlUrl?: string;
17
    subject: string;
18
    replyTo?: string;
19
    toField?: string;
20
    attachmentUrl?: string;
21
    isActive?: false | true;
22
  },
23
) {
24
  const url = new URL(`https://api.brevo.com/v3/smtp/templates`);
25

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