Unable To Create An Event With Microsoft Graph API

Viewed 1003

I'm trying to create an Event using The Microsoft Graph API in .Net 5 with ASP.

I have been to The Graph Explorer and as weird as its sounds,
sometimes but not always an event wont create using the demo code provided (see below)

{
    "subject": "My event 0",
    "start": {
        "dateTime": "2021-04-09T00:00:36.595Z",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2021-04-16T00:00:36.595Z",
        "timeZone": "UTC"
    }
}

"error": { "code": "RequestBodyRead", "message": "The property 'subject' does not exist on type 'Microsoft.OutlookServices.Event'. Make sure to only use property names that are defined by the type or mark the type as open type. REST APIs for this mailbox are currently in preview. You can find more information about the preview REST APIs at https://dev.outlook.com/." } }


Here is the payload of an Event object I am attempt to create an event with.

{
      "allowNewTimeProposals": true,
      "attendees": [
        {
          "type": "required",
          "emailAddress": {
            "address": "andrew@andrew.com",
            "@odata.type": "microsoft.graph.emailAddress"
          },
          "@odata.type": "microsoft.graph.attendee"
        }
      ],
      "body": {
       "content": "hello,world",
       "contentType": "html",
       "@odata.type": "microsoft.graph.itemBody"
       },
      "end": {
      "dateTime": "2021-04-10T11:11:00.0000000",
      "timeZone": "AUS Eastern Standard Time",
      "@odata.type": "microsoft.graph.dateTimeTimeZone"
      },
      "isAllDay": false,
      "location": {
        "displayName": "Microsoft Teams Meeting",
        "@odata.type": "microsoft.graph.location"
       },
      "start": {
        "dateTime": "2021-04-10T11:10:00.0000000",
        "timeZone": "AUS Eastern Standard Time",
        "@odata.type": "microsoft.graph.dateTimeTimeZone"
      },
      "subject": "Andrew",
      "@odata.type": "microsoft.graph.event"
    }

Status Code: BadRequest Microsoft.Graph.ServiceException: Code: RequestBodyRead Message: A type named 'microsoft.graph.event' could not be resolved by the model. When a model is available, each type name must resolve to a valid type. REST APIs for this mailbox are currently in preview. You can find more information about the preview REST APIs at https://dev.outlook.com/.


It might be worth mentioning that so far all other requests both Get & Post have been successful when using the SDK/API.

Scopes used

        public readonly static string[] Scopes =
        {
            "User.Read",
            "MailboxSettings.Read",
            "Calendars.ReadWrite",
        };

Code Used To Send The Request.

        var timeZone = User.FindFirst("graph_timezone").Value;

        var @event = new Event()
        {
            Subject = teamsMeetingRequest.Title,
            Attendees = attendees,
            IsAllDay = teamsMeetingRequest.IsAllDay,
            Start = new DateTimeTimeZone
            {
                DateTime = teamsMeetingRequest.StartDate.ToString("o"),
                TimeZone = timeZone
            },
            End = new DateTimeTimeZone
            {
                DateTime = teamsMeetingRequest.EndDate.ToString("o"),
                TimeZone = timeZone
            },
            Body = new ItemBody()
            {
                Content = teamsMeetingRequest.Body,
                ContentType = BodyType.Html,
            },
            Location = new Location()
            {
                DisplayName = "Microsoft Teams Meeting"
            },
            AllowNewTimeProposals = true
        };

        await this._graphClient.Me.Events.Request().AddAsync(@event);

Update StackTrace

All other error's in both The Graph Explorer And Response From The SDK/API Are Mentioned Above.

Status Code: BadRequest Microsoft.Graph.ServiceException:
Code: RequestBodyRead
Message: A type named 'microsoft.graph.event' could not be resolved 
  by the model. When a model is available, each type name must resolve 
  to a valid type. REST APIs for this mailbox are currently in preview. 
  You can find more information about the preview REST APIs at https://dev.outlook.com/.
Inner error:    
AdditionalData:     
date: 2021-04-10T02:46:11   
request-id: removed for question    
client-request-id: removed for question 
ClientRequestId: removed for question
   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at TeamsMeetingCreator.Controllers.ValuesController.CreateTeamsMeeting(TeamsMeetingRequest teamsMeetingRequest) in Path To My File.


Update
I have tried POSTMAN to send the request with the above payloads so there shouldnt be any ODataType issues but unfortunately the same error exists.

"The property 'subject' does not exist on type 'Microsoft.OutlookServices.Event'

Update
I have tried creating an Event with no properties and it has successfully created, I then tried to Update the event

// Update The Event.
@event = await this._graphClient.Me.Events[emptyEvent.Id].Request().UpdateAsync(@event);

However the same error is returned

The property 'attendees' does not exist on type 'Microsoft.OutlookServices.Event

1 Answers

This is probably a bug in the client library. Try this before doing AddAsync:

@event.ODataType = null;
Related