1 | type Convertkit = { |
2 | apiSecret: string |
3 | } |
4 |
|
5 | export async function main( |
6 | resource: Convertkit, |
7 | payload: { |
8 | content?: string |
9 | description?: string |
10 | email?: string |
11 | emailLayoutTemplate?: string |
12 | isPublic?: boolean |
13 | publishedAt?: string |
14 | sendAt?: string |
15 | subject?: string |
16 | thumbnailAlt?: string |
17 | thumbnailUrl?: string |
18 | } |
19 | ) { |
20 | const endpoint = `https://api.convertkit.com/v3/broadcasts` |
21 |
|
22 | const body = { |
23 | api_secret: resource.apiSecret, |
24 | content: payload.content, |
25 | description: payload.description, |
26 | email_address: payload.email, |
27 | email_layout_template: payload.emailLayoutTemplate, |
28 | public: payload.isPublic, |
29 | published_at: payload.publishedAt, |
30 | send_at: payload.sendAt, |
31 | subject: payload.subject, |
32 | thumbnail_alt: payload.thumbnailAlt, |
33 | thumbnail_url: payload.thumbnailUrl |
34 | } |
35 |
|
36 | const response = await fetch(endpoint, { |
37 | method: 'POST', |
38 | headers: { |
39 | 'Content-Type': 'application/json' |
40 | }, |
41 | body: JSON.stringify(body) |
42 | }) |
43 |
|
44 | if (!response.ok) { |
45 | throw new Error(`HTTP error! status: ${response.status}`) |
46 | } |
47 |
|
48 | const data = await response.json() |
49 | return data.broadcast |
50 | } |
51 |
|