0

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

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