//native
/**
* List Event Instances
* List the occurrences of a recurring event, each with its own instance id (for Update Event Instance / Update Following Instances). Bound the range with RFC 3339 `time_min`/`time_max` (an unbounded series has no end). Pass the returned `nextPageToken` as `page_token` for the next page.
*/
export async function main(
auth: RT.Gcal,
recurring_event_id: string,
calendar_id: string = "primary",
time_min: string | undefined,
time_max: string | undefined,
show_deleted: boolean = false,
max_results: number = 250,
page_token: string | undefined
) {
const url = new URL(
`https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendar_id || "primary")}/events/${recurring_event_id}/instances`
)
url.searchParams.append("showDeleted", String(!!show_deleted))
url.searchParams.append("maxResults", String(max_results || 250))
for (const [k, v] of [
["timeMin", time_min],
["timeMax", time_max],
["pageToken", page_token],
]) {
if (v != null && v !== "") url.searchParams.append(k!, v)
}
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 hours ago