1 | type Convertkit = { |
2 | apiSecret: string |
3 | } |
4 |
|
5 | export async function main(resource: Convertkit, broadcastId: string) { |
6 | |
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 |
|