Judith Ting
Judith Ting

Reputation: 119

Get 'UnableToDeserializePostBody' error after sending a post request to Microsoft Germany endpoint

After sending the following post request to Microsoft Germany endpoint (https://graph.microsoft.de/v1.0), I got 400 UnableToDeserializePostBody, but I received 201 after I sent the same request to Microsoft Graph endpoint (https://graph.microsoft.com/v1.0).

Is there limitation on Germany endpoint?

Request POST https://graph.microsoft.de/v1.0/users/xxx/events/

{
    "attendees":[],
    "body":{
        "content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=iso-2022-jp\">\r\n<style type=\"text/css\" style=\"display:none\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" dir=\"ltr\" style=\"font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif\">\r\n<p style=\"margin-top:0; margin-bottom:0\"><br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n",
        "contentType":"html"
    },
    "bodyPreview":"",
    "categories":[],
    "changeKey":"V3BbxVnFKUiKHwfECS7njQABscz/wA==",
    "createdDateTime":"2020-06-22T08:04:02.7260413Z",
    "end": {
        "dateTime":"2020-06-23T00:30:00.0000000",
        "timeZone":"UTC"
    },
    "hasAttachments":false,
    "iCalUId":"",
    "id":"AAMkADY5ODA5YjI4LTZlMmEtNDk5My1hNTcxLTFmMDJlMTFlM2ZmYQBGAAAAAADXELVefACVTqbk5n3dmlnfBwBXcFvFWcUpSIofB8QJLueNAAGx1uUKAABXcFvFWcUpSIofB8QJLueNAAGx1vTOAAA=",
    "importance":"normal",
    "isAllDay":false,
    "isCancelled":false,
    "isOrganizer":true,
    "isReminderOn":true,
    "lastModifiedDateTime":"2020-06-22T08:04:03.3837944Z",
    "location":{
        "address":{
            "city":"",
            "countryOrRegion":"",
            "postalCode":"",
            "state":"",
            "street":""
        }, 
        "coordinates":{}, 
        "locationType":"default",
        "uniqueIdType":"unknown"
    },
    "onlineMeetingUrl":"",
    "organizer":{
        "emailAddress":{
            "address":"a@b",
            "name":"test"
        }
    },
    "originalEndTimeZone":"Taipei Standard Time",
    "originalStart":null,
    "originalStartTimeZone":"Taipei Standard Time",
    "recurrence":null,
    "reminderMinutesBeforeStart":15,
    "responseRequested":true,
    "responseStatus":{
        "response":"organizer",
        "time":"0001-01-01T00:00:00Z"
    },
    "sensitivity":"normal",
    "seriesMasterId":"",
    "showAs":"busy",
    "start":{
        "dateTime":"2020-06-23T00:00:00.0000000",
        "timeZone":"UTC"
    },
    "subject":"1",
    "type":"singleInstance",
    "webLink":"https://outlook.office.de/owa/?itemid=AAMkADY5ODA5YjI4LTZlMmEtNDk5My1hNTcxLTFmMDJlMTFlM2ZmYQBGAAAAAADXELVefACVTqbk5n3dmlnfBwBXcFvFWcUpSIofB8QJLueNAAGx1uUKAABXcFvFWcUpSIofB8QJLueNAAGx1vTOAAA%3D&exvsurl=1&path=/calendar/item"
}

Response from Germany endpoint 400 Bad Request

{
    "error": {
        "code": "UnableToDeserializePostBody",
        "message": "were unable to deserialize ",
        "innerError": {
            "date": "2020-08-07T08:44:52",
            "request-id": "ce4c6d23-9163-42a1-9839-787596f7533b"
        }
    }
}

Upvotes: 4

Views: 7758

Answers (3)

Tatiana Racheva
Tatiana Racheva

Reputation: 1304

Another reason you may get a UnableToDeserializePostBody from this endpoint is the recurrence startDate/endDate - they cannot be in the DateTime format.

In other words, a date in the ISO8601 format ("yyyy-MM-ddTHH:mm:ss") will also cause this error.

The date should be formatted as "yyyy-MM-dd".

Can't believe it's that picky, especially since the documentation insists the date has to match the event dateTime, but that's how it is.

Upvotes: 0

Christopher Reece
Christopher Reece

Reputation: 396

I ran into the same issue, and as louisl mentioned it was a problem with using the wrong primitive types in the request object.

I found this library of Typescript Types for the Microsoft Graph Client: https://github.com/microsoftgraph/msgraph-typescript-typings. This library provided the "Event" type, which is what I believe you're using.

Below is a snippet of Typescript that helped me ensure my request object was correct. Notice the Event import and the explicit typing of the eventRequest constant.

import { Event, Attendee } from '@microsoft/microsoft-graph-types'

      const eventRequest: Event = {
        subject: name,
        body: {
          contentType: 'html',
          content: ...
        },
        ...
      }

If you're using VSCode and a Mac you can command + click on the type to look at the definition directly, so you can see what properties are optional, and what types they require. I found Microsoft's type library and in-line comments to be more up-to-date than the official documentation.

It's really useful to explore the type file to get a better idea of how the Microsoft Client works. This principle has been helpful with other libraries as well.

Upvotes: 1

louisl
louisl

Reputation: 99

You've probably given up or fixed it by now but I just had this error when setting color. I used an integer but when I changed to string it was ok.

I notice you have "reminderMinutesBeforeStart":15 try it as "reminderMinutesBeforeStart":"15".

Upvotes: 2

Related Questions