//native
type Calendly = {
token: string
}
export async function main(
auth: Calendly,
body: {
url: string
events:
| 'invitee.canceled'
| 'invitee.created'
| 'invitee_no_show.created'
| 'invitee_no_show.deleted'
| 'routing_form_submission.created'[]
organization: string
user?: string
group?: string
scope: 'organization' | 'user' | 'group'
signing_key?: string
}
) {
const url = new URL(`https://api.calendly.com/webhook_subscriptions`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 28 days ago