0

Create a Group

by
Published Aug 26, 2024
Script mailerlite Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 652 days ago
1
type Mailerlite = {
2
	apiToken: string
3
}
4

5
export async function main(resource: Mailerlite, name: string) {
6
	const endpoint = `https://connect.mailerlite.com/api/groups`
7

8
	const body = { name }
9

10
	const response = await fetch(endpoint, {
11
		method: 'POST',
12
		headers: {
13
			'Content-Type': 'application/json',
14
			Accept: 'application/json',
15
			Authorization: `Bearer ${resource.apiToken}`
16
		},
17
		body: JSON.stringify(body)
18
	})
19

20
	if (!response.ok) {
21
		throw new Error(`HTTP error! status: ${response.status}`)
22
	}
23

24
	const { data } = await response.json()
25

26
	return data
27
}
28