0
Broadcast Stats
One script reply has been approved by the moderators Verified

Get broadcast stats

Created by hugo697 80 days ago Viewed 29 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, broadcastId: string) {
6
	// Construct the query parameters.
7
	const queryParams = new URLSearchParams({
8
		api_secret: resource.apiSecret
9
	})
10

11
	const endpoint = `https://api.convertkit.com/v3/broadcasts/${broadcastId}/stats?${queryParams.toString()}`
12

13
	const response = await fetch(endpoint, {
14
		method: 'GET',
15
		headers: {
16
			'Content-Type': 'application/json'
17
		}
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.broadcast
27
}
28