0

Create Newsletter

by
Published Apr 8, 2025
Script buttondown Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Buttondown = {
3
  token: string;
4
};
5
/**
6
 * Create Newsletter
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  body: {
12
    username: string;
13
    name: string;
14
    description: string;
15
    tint_color?: string;
16
    from_name?: string;
17
    header?: string;
18
    footer?: string;
19
    domain?: string;
20
    email_domain?: string;
21
    enabled_features?: string[];
22
    custom_email_template?: string;
23
  },
24
) {
25
  const url = new URL(`https://api.buttondown.com/v1/newsletters`);
26

27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Token " + auth.token,
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.json();
40
}
41