//native
type Calendly = {
token: string
}
export async function main(
auth: Calendly,
user: string | undefined,
organization: string | undefined,
invitee_email: string | undefined,
status: 'active' | 'canceled' | undefined,
sort: string | undefined,
min_start_time: string | undefined,
max_start_time: string | undefined,
page_token: string | undefined,
count: string | undefined,
group: string | undefined
) {
const url = new URL(`https://api.calendly.com/scheduled_events`)
for (const [k, v] of [
['user', user],
['organization', organization],
['invitee_email', invitee_email],
['status', status],
['sort', sort],
['min_start_time', min_start_time],
['max_start_time', max_start_time],
['page_token', page_token],
['count', count],
['group', group]
]) {
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 51 days ago