0

List Calendars

by
Published today

List the connected account's calendars, including shared ones it has added. 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
 * List Calendars
5
 * List the connected account's calendars, including shared ones it has added. Requires Calendars.Read (covered by the default Calendars.ReadWrite).
6
 */
7
export async function main(
8
  auth: RT.Outlook,
9
  top: number = 100,
10
  next_link: string | undefined
11
) {
12
  if (
13
    next_link != null &&
14
    next_link !== "" &&
15
    !next_link.startsWith("https://graph.microsoft.com/")
16
  ) {
17
    throw new Error(
18
      "next_link must be an @odata.nextLink returned by Microsoft Graph"
19
    )
20
  }
21
  let url: URL
22
  if (next_link != null && next_link !== "") {
23
    url = new URL(next_link)
24
  } else {
25
    url = new URL("https://graph.microsoft.com/v1.0/me/calendars")
26
    url.searchParams.append("$top", String(top))
27
  }
28

29
  const response = await fetch(url, {
30
    headers: {
31
      Authorization: `Bearer ${auth.token}`,
32
      Accept: "application/json",
33
    },
34
  })
35

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

40
  return await response.json()
41
}
42