type Convertkit = {
apiSecret: string
}
export async function main(
resource: Convertkit,
payload: {
targetUrl: string
event: {
name: string
[key: string]: any
}
}
) {
const endpoint = `https://api.convertkit.com/v3/automations/hooks`
const body = {
api_secret: resource.apiSecret,
target_url: payload.targetUrl,
event: payload.event
}
const response = await fetch(endpoint, {
method: 'POST',
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.rule
}
Submitted by hugo697 81 days ago