Search code examples
microsoft-graph-apimicrosoft-graph-calendar

Get events without start and end date


In the Microsoft Graph Calendar API I can get all events with the request url:

/me/calendarView/delta?startDateTime={start_datetime}&endDateTime={end_datetime}

But I have to specify a start and end date. Is there a way to just get all events without specifying the dates?

Just leaving the dates out of the request gives me an error that it is missing those parameters.


Solution

  • The /calendarView endpoint is designed to give you a rendered view of a calendar for a given date range. Without a date range, the API would have to render every event in the calendar, potentially going back decades. The computational cost of doing that could be excessively high, not to mention the negative impact it would have on performance at scale.

    If you just want the raw underlying event objects, you can use the /events endpoint. This will give you paged results containing every event in that calendar. You will need to do some post-processing to render individual instances for repeating events based on the master event (i.e. events with "eventType": "seriesMaster").

    In general, I would recommend using /calendarView since it handles rendering the series instances for you. You can effectively imitate retrieving "everything" by passing it a sufficiently large window, albeit with a performance hit.

    To illustrate, calling the following URI in Graph Explorer returns a full decade (2009-2019) of events:

    https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2009-01-01&enddatetime=2019-12-31
    

    It's worth noting that this took 6,436 milliseconds to return a result and the data only contains a small number of events. When I ran this same query against my calendar it took 13,883 milliseconds. So purely from a performance perspective, I wouldn't recommend regularly querying for more than 12 months at a time (i.e. startdatetime=2018-01-01&enddatetime=2018-12-31 took 2795ms).