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

Create a tag

Created by hugo697 24 days ago Viewed 11 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 24 days ago
1
type Convertkit = {
2
	apiSecret: string
3
}
4

5
export async function main(
6
	resource: Convertkit,
7
	tags: {
8
		name: string
9
	}[]
10
) {
11
	const endpoint = `https://api.convertkit.com/v3/tags`
12

13
	const body = {
14
		api_secret: resource.apiSecret,
15
		tag: tags
16
	}
17

18
	const response = await fetch(endpoint, {
19
		method: 'POST',
20
		headers: {
21
			'Content-Type': 'application/json'
22
		},
23
		body: JSON.stringify(body)
24
	})
25

26
	if (!response.ok) {
27
		throw new Error(`HTTP error! status: ${response.status}`)
28
	}
29

30
	const data = await response.json()
31
	return data
32
}
33