Search code examples
outlookoffice365office365apioutlook-restapi

How can I create a new category in Office 365 calendar using the REST API?


The application I am currently working on adds new events in the user's Office 365 calendar. I would like to display the events in different colors based on some criteria. I think I can achieve that using categories but I didn't find a way to add a new category or at least get a list of the available categories in the user's calendar.
I read the documentation available here but it doesn't say anything related to categories.


Solution

  • We added category support in the beta version of the Microsoft Graph API.

    Announcement: https://blogs.msdn.microsoft.com/exchangedev/2017/10/09/new-outlook-apis-in-the-microsoft-graph-rooms-rules-categories-headers-and-time-zones/

    Beta reference: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/outlookuser_post_mastercategories

    Example:

    POST https://graph.microsoft.com/beta/me/outlook/masterCategories
    Content-type: application/json
    Content-Length: 70
    
    {
          "displayName":"Project expenses",
          "color":"preset9"
    }
    

    You can do similar operations using the Outlook REST API using a URL like:

    https://outlook.office.com/api/beta/me/mastercategories
    

    There's also a new permission scope that you need for this. For Graph, it's MailboxSettings.ReadWrite (https://outlook.office.com/MailboxSettings.ReadWrite for the Outlook API).