0

Update 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
 * Update Newsletter
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  id: string,
12
  body: {
13
    username?: string;
14
    name?: string;
15
    description?: string;
16
    tint_color?: string;
17
    from_name?: string;
18
    header?: string;
19
    footer?: string;
20
    domain?: string;
21
    email_domain?: string;
22
    enabled_features?: string[];
23
    custom_email_template?: string;
24
  },
25
) {
26
  const url = new URL(`https://api.buttondown.com/v1/newsletters/${id}`);
27

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