0
Get Subscriber By Email
One script reply has been approved by the moderators Verified

Returns data for a single subscriber

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

5
export async function main(resource: Convertkit, email: string) {
6
	// Construct the query parameters.
7
	const queryParams = new URLSearchParams({
8
		api_secret: resource.apiSecret,
9
		email_address: email
10
	})
11

12
	const endpoint = `https://api.convertkit.com/v3/subscribers?${queryParams.toString()}`
13

14
	const response = await fetch(endpoint, {
15
		method: 'GET',
16
		headers: {
17
			'Content-Type': 'application/json'
18
		}
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.subscribers[0]
28
}
29