0

Get Free/Busy Schedule

by
Published today

Get the free/busy availability of users, distribution lists or rooms (by email address) over a window of local times in `time_zone`. Requires Calendars.Read (covered by the default Calendars.ReadWrite).

Script outlook Verified

The script

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

3
/**
4
 * Get Free/Busy Schedule
5
 * Get the free/busy availability of users, distribution lists or rooms (by email address) over a window of local times in `time_zone`. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  schedules: string[],
10
  start: string,
11
  end: string,
12
  time_zone: string = "UTC",
13
  availability_view_interval: number = 30
14
) {
15
  const response = await fetch(
16
    "https://graph.microsoft.com/v1.0/me/calendar/getSchedule",
17
    {
18
      method: "POST",
19
      headers: {
20
        Authorization: `Bearer ${auth.token}`,
21
        "Content-Type": "application/json",
22
        Accept: "application/json",
23
        Prefer: `outlook.timezone="${time_zone}"`,
24
      },
25
      body: JSON.stringify({
26
        schedules,
27
        startTime: { dateTime: start, timeZone: time_zone },
28
        endTime: { dateTime: end, timeZone: time_zone },
29
        availabilityViewInterval: availability_view_interval,
30
      }),
31
    }
32
  )
33

34
  if (!response.ok) {
35
    throw new Error(`${response.status} ${await response.text()}`)
36
  }
37

38
  return await response.json()
39
}
40