0

Create Bulk Action

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 Bulk Action
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  body: {
12
    type:
13
      | "apply_tags"
14
      | "apply_metadata"
15
      | "ban_subscribers"
16
      | "delete_subscribers"
17
      | "gift_subscribers"
18
      | "reactivate_subscribers"
19
      | "mark_subscribers_as_not_spammy"
20
      | "resubscribe_subscribers"
21
      | "send_emails"
22
      | "unsubscribe_subscribers"
23
      | "send_reminders"
24
      | "delete_emails"
25
      | "update_email_types"
26
      | "delete_tags"
27
      | "delete_surveys"
28
      | "replay_events"
29
      | "delete_comments"
30
      | "update_survey_statuses";
31
    metadata: {};
32
  },
33
) {
34
  const url = new URL(`https://api.buttondown.com/v1/bulk_actions`);
35

36
  const response = await fetch(url, {
37
    method: "POST",
38
    headers: {
39
      "Content-Type": "application/json",
40
      Authorization: "Token " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50