0

Get Event

by
Published today

Get one calendar event by id, with start and end times expressed in `time_zone`. 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
 * Get Event
5
 * Get one calendar event by id, with start and end times expressed in `time_zone`. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
6
 */
7
export async function main(
8
  auth: RT.MsOutlook,
9
  event_id: string,
10
  select: string | undefined,
11
  time_zone: string = "UTC"
12
) {
13
  const url = new URL(
14
    `https://graph.microsoft.com/v1.0/me/events/${encodeURIComponent(event_id)}`
15
  )
16
  if (select != null && select !== "") {
17
    url.searchParams.append("$select", select)
18
  }
19

20
  const response = await fetch(url, {
21
    headers: {
22
      Authorization: `Bearer ${auth.token}`,
23
      Accept: "application/json",
24
      Prefer: `outlook.timezone="${time_zone}"`,
25
    },
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34