colorscalendarmicrosoft-graph-api

getting color off calendar in microsoft graph api in calendarview


I am using the calendarview in the microsoft graph api, using the following url: https://graph.microsoft.com/v1.0/me/calendars/'+calendarId+'/calendarView?$select=subject,bodyPreview,start,end,location,isAllDay,lastModifiedDateTime,iCalUId,categories

Everything works, I get the data I need, but I would at the same time like to get the color and hexcolor of the calendar, but I am not sure how to do that, so I hope someone else can help with it,

I tried adding ,calendar to the $select part but without it giving me anything back about the calendar these events belong to.

I see here: https://learn.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0 that I should be able to do it if I understand this correct, so I hope someone can help.


Solution

  • The CalendarView will only ever return event objects (or the underlying calendar items in Exchange). The Calendar color property only exists on the Calendar and is not a property of the events themselves. With your request

    https://graph.microsoft.com/v1.0/me/calendars/'+calendarId+'/calendarView?$select=subject,bodyPreview,start,end,location,isAllDay,lastModifiedDateTime,iCalUId,categories
    

    This will only return events from the calendar with the calendarId your passing in so if you want the calendar color you just need to make a separate request on the calendar endpoint eg a Get to

    https://graph.microsoft.com/v1.0/me/calendars/'+calendarId+