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

Update a broadcast

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(
6
	resource: Convertkit,
7
	broadcastId: string,
8
	payload: {
9
		content?: string
10
		description?: string
11
		email?: string
12
		emailLayoutTemplate?: string
13
		isPublic?: boolean
14
		publishedAt?: string
15
		sendAt?: string
16
		subject?: string
17
		thumbnailAlt?: string
18
		thumbnailUrl?: string
19
	}
20
) {
21
	const endpoint = `https://api.convertkit.com/v3/broadcasts/${broadcastId}`
22

23
	const body = {
24
		api_secret: resource.apiSecret,
25
		content: payload.content,
26
		description: payload.description,
27
		email_address: payload.email,
28
		email_layout_template: payload.emailLayoutTemplate,
29
		public: payload.isPublic,
30
		published_at: payload.publishedAt,
31
		send_at: payload.sendAt,
32
		subject: payload.subject,
33
		thumbnail_alt: payload.thumbnailAlt,
34
		thumbnail_url: payload.thumbnailUrl
35
	}
36

37
	const response = await fetch(endpoint, {
38
		method: 'PUT',
39
		headers: {
40
			'Content-Type': 'application/json'
41
		},
42
		body: JSON.stringify(body)
43
	})
44

45
	if (!response.ok) {
46
		throw new Error(`HTTP error! status: ${response.status}`)
47
	}
48

49
	const data = await response.json()
50
	return data.broadcast
51
}
52