0

Create Export

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 Export
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  body: {
12
    collections:
13
      | "subscribers"
14
      | "emails"
15
      | "events"
16
      | "referrals"
17
      | "surveys"
18
      | "comments"
19
      | "requests"
20
      | "mentions"
21
      | "conversations"[];
22
    parameters?: {};
23
    columns?: string[];
24
  },
25
) {
26
  const url = new URL(`https://api.buttondown.com/v1/exports`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
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