0
Remove Tag From Subscriber By Email
One script reply has been approved by the moderators Verified

Remove a tag from a subscriber by email

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

5
export async function main(resource: Convertkit, tagId: string, email: string) {
6
	const endpoint = `https://api.convertkit.com/v3/tags/${tagId}/unsubscribe`
7

8
	const body = {
9
		api_secret: resource.apiSecret,
10
		email
11
	}
12

13
	const response = await fetch(endpoint, {
14
		method: 'POST',
15
		headers: {
16
			'Content-Type': 'application/json; charset=utf-8'
17
		},
18
		body: JSON.stringify(body)
19
	})
20

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

25
	const data = await response.json()
26

27
	return data
28
}
29