0

List Event Instances

by
Published today

List the occurrences of a recurring event (its series master id) between two ISO 8601 date-times. Each occurrence has its own id: pass it to Update Event or Delete Event to change or cancel that single occurrence. Requires Calendars.Read (covered by the default Calendars.ReadWrite).

Script ms_outlook Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * List Event Instances
5
 * List the occurrences of a recurring event (its series master id) between two ISO 8601 date-times. Each occurrence has its own id: pass it to Update Event or Delete Event to change or cancel that single occurrence. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
6
 */
7
export async function main(
8
  auth: RT.MsOutlook,
9
  event_id: string,
10
  start_date_time: string,
11
  end_date_time: string,
12
  top: number = 25,
13
  next_link: string | undefined,
14
  time_zone: string = "UTC"
15
) {
16
  if (
17
    next_link != null &&
18
    next_link !== "" &&
19
    !next_link.startsWith("https://graph.microsoft.com/")
20
  ) {
21
    throw new Error(
22
      "next_link must be an @odata.nextLink returned by Microsoft Graph"
23
    )
24
  }
25
  let url: URL
26
  if (next_link != null && next_link !== "") {
27
    url = new URL(next_link)
28
  } else {
29
    url = new URL(
30
      `https://graph.microsoft.com/v1.0/me/events/${encodeURIComponent(
31
        event_id
32
      )}/instances`
33
    )
34
    url.searchParams.append("startDateTime", start_date_time)
35
    url.searchParams.append("endDateTime", end_date_time)
36
    url.searchParams.append("$top", String(top))
37
  }
38

39
  const response = await fetch(url, {
40
    headers: {
41
      Authorization: `Bearer ${auth.token}`,
42
      Accept: "application/json",
43
      Prefer: `outlook.timezone="${time_zone}"`,
44
    },
45
  })
46

47
  if (!response.ok) {
48
    throw new Error(`${response.status} ${await response.text()}`)
49
  }
50

51
  return await response.json()
52
}
53