voidmain
voidmain

Reputation: 1611

With Exchange Web Services a calendar event can be created and assigned to a specific category while that same capability is missing from Graph

I have been using EWS to create appointments in both Exchange on-premise and Exchange online mailboxes that include a category value. I'm trying to migrate to Microsoft Graph since it's the recommended path according to Microsoft https://learn.microsoft.com/en-us/graph/migrate-exchange-web-services-overview

One of the EWS capabilities I can't replicate is creating a calendar event with a category.

The EWS Appointment class supports setting the category for the appointment - https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.appointment?view=exchange-ews-api

When testing with Graph to create a calendar event, all responses to the posted requests include a null categories array as shown in the documentation - https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=csharp so it would seem that a request can be made with category.

Using the Microsoft Graph explorer to create a calendar event I naively add the categories property as an array and include a known category from the user's mailbox:

{
  "subject": "Test",
  "isAllDay": true,
  "ShowAs":"Free",
  "categories": [
    { "displayName":"Red Category", "color": "preset0" },
  ],
  "start": {
        "dateTime": "2022-11-08T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    },
    "end": {
        "dateTime": "2022-11-09T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    }
}

The response is always:

{
  "error": {
    "code": "UnableToDeserializePostBody",
    "message": "were unable to deserialize "
  }
}

I have also changed the property to a key:value which gets the same reponse.

{
  "subject": "Test",
  "isAllDay": true,
  "ShowAs":"Free",
  "category": "Red Category",
  "start": {
        "dateTime": "2022-11-08T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    },
    "end": {
        "dateTime": "2022-11-09T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    }
}

Does the Graph Create Event POST /users/{id | userPrincipalName}/calendars/{id}/events support including a category?

Upvotes: 0

Views: 410

Answers (1)

GavinB
GavinB

Reputation: 595

You were so close.

Categories is an array of strings. This will create the appointment with the Personal category, if there is no Personal category one will be created.

{
    "subject": "Test",
    "isAllDay": true,
    "ShowAs": "Free",
    "categories": [
        "Personal"
    ],
    "start": {
        "dateTime": "2022-11-08T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    },
    "end": {
        "dateTime": "2022-11-09T00:00:00.0000000",
        "timeZone": "Eastern Standard Time"
    }
}

Upvotes: 1

Related Questions