type Convertkit = {
apiSecret: string
}
export async function main(
resource: Convertkit,
broadcastId: string,
payload: {
content?: string
description?: string
email?: string
emailLayoutTemplate?: string
isPublic?: boolean
publishedAt?: string
sendAt?: string
subject?: string
thumbnailAlt?: string
thumbnailUrl?: string
}
) {
const endpoint = `https://api.convertkit.com/v3/broadcasts/${broadcastId}`
const body = {
api_secret: resource.apiSecret,
content: payload.content,
description: payload.description,
email_address: payload.email,
email_layout_template: payload.emailLayoutTemplate,
public: payload.isPublic,
published_at: payload.publishedAt,
send_at: payload.sendAt,
subject: payload.subject,
thumbnail_alt: payload.thumbnailAlt,
thumbnail_url: payload.thumbnailUrl
}
const response = await fetch(endpoint, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data.broadcast
}
Submitted by hugo697 81 days ago