//native
type Calendly = {
token: string
}
export async function main(
auth: Calendly,
organization: string | undefined,
user: string | undefined,
group: string | undefined,
page_token: string | undefined,
count: string | undefined,
sort: string | undefined,
scope: 'organization' | 'user' | 'group' | undefined
) {
const url = new URL(`https://api.calendly.com/webhook_subscriptions`)
for (const [k, v] of [
['organization', organization],
['user', user],
['group', group],
['page_token', page_token],
['count', count],
['sort', sort],
['scope', scope]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 2 days ago