0
Create Subscriber List
One script reply has been approved by the moderators Verified

Creates a new subscriber list.

Created by hugo697 41 days ago Viewed 10 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 41 days ago
1
type Acumbamail = {
2
	authToken: string
3
}
4

5
export async function main(
6
	resource: Acumbamail,
7
	body: {
8
		name: string
9
		sender_email: string
10
		company?: string
11
		country?: string
12
		city?: string
13
		address?: string
14
		phone?: string
15
	}
16
) {
17
	const endpoint = 'https://acumbamail.com/api/1/createList/'
18

19
	const formData = new FormData()
20

21
	formData.append('auth_token', resource.authToken)
22
	formData.append('name', body.name)
23
	formData.append('sender_email', body.sender_email)
24
	formData.append('company', body.company ?? '')
25
	formData.append('country', body.country ?? '')
26
	formData.append('city', body.city ?? '')
27
	formData.append('address', body.address ?? '')
28
	formData.append('phone', body.phone ?? '')
29

30
	const response = await fetch(endpoint, {
31
		method: 'POST',
32
		headers: {
33
			'Cache-Control': 'no-cache'
34
		},
35
		body: formData
36
	})
37

38
	if (!response.ok) {
39
		throw new Error(`HTTP error! status: ${response.status}`)
40
	}
41

42
	const data = await response.json()
43

44
	return data
45
}
46