forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflodesk.ts
More file actions
32 lines (31 loc) · 824 Bytes
/
flodesk.ts
File metadata and controls
32 lines (31 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export async function subscribe({
email,
name,
}: {
email: string;
name?: string | null;
}) {
return fetch("https://api.flodesk.com/v1/subscribers", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${process.env.FLODESK_API_KEY}`,
},
body: JSON.stringify({
email,
...(name && {
first_name: name.split(" ")[0],
last_name: name.split(" ").slice(1).join(" "),
}),
}),
}).then((res) => res.json());
}
export async function unsubscribe(email: string) {
return fetch(`https://api.flodesk.com/v1/subscribers/${email}/unsubscribe`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${process.env.FLODESK_API_KEY}`,
},
}).then((res) => res.json());
}