Malte
Malte

Reputation: 3

Can't create new events with Office 365 API

I am using the the Calendar REST in Office 365 API and I try to post a event according to the example in: http://msdn.microsoft.com/en-us/library/office/dn792114(v=office.15).aspx

The response I get is

{error: {code: "ErrorInvalidRequest" message: "Cannot read the request body."} }

when I post with Avanced Rest Client to URL https://outlook.office365.com/ews/odata/Me/Events with Content-Type: application/json and I'm using an office365 service account.

The JSON I post is copied from the example in the link above

{
  "@odata.type": "#Microsoft.Exchange.Services.OData.Model.Event",
  "Subject": "Discuss the Calendar REST API",
  "Body": {
    "ContentType": "HTML",
    "Content": "I think it will meet our requirements!"
  },
  "Start": "2014-07-02T18:00:00Z",
  "End": "2014-07-02T19:00:00Z",
  "Location": {
      "DisplayName": "Conference Room 1"
    },
  "ShowAs": "Busy",
  "Attendees": [
    {
      "Name": "Alex Darrow",
      "Address": "[email protected]",
      "Type": "Required"
    },
    {
      "Name": "Anne Wallace",
      "Address": "[email protected]",
      "Type": "Optional"
    },
    {
      "Name": "Conference Room 1",
      "Address": "[email protected]",
      "Type": "Resource"
    }
  ]
}

If "@odata.type": "#Microsoft.Exchange.Services.OData.Model.Event" is removed together with "Attendees" the post is successful.

If anyone could help out would be much appreciated.

Upvotes: 0

Views: 1574

Answers (1)

Venkat Ayyadevara - MSFT
Venkat Ayyadevara - MSFT

Reputation: 2893

Thanks for your mail and sorry for the inconvenience! Below is a modified version of your request that should work. I have made two changes. The list of Attendees now includes a type called EmailAddress. I have also omitted @odata.type as you don't have to include it and since you are posting to a collection, the type is inferred by our service. The namespace for Mail, Calendar and Contacts have been updated from "#Microsoft.Exchange.Services.OData.Model" to "#Microsoft.OutlookServices" and this is why @odata.type was returning an error for you.

{
  "Subject": "Discuss the Calendar REST API",
  "Body": {
    "ContentType": "HTML",
    "Content": "I think it will meet our requirements!"
  },
  "Start": "2014-07-02T18:00:00Z",
  "End": "2014-07-02T19:00:00Z",
  "Location": {
      "DisplayName": "Conference Room 1"
    },
  "ShowAs": "Busy",
  "Attendees": [
    {
      "EmailAddress": { "Name": "Alex Darrow", "Address": "[email protected]" },
      "Type": "Required"
    },
    {
      "EmailAddress": { "Name": "Anne Wallace", "Address": "[email protected]"},
      "Type": "Optional"
    },
    {
      "EmailAddress": { "Name": "Conference Room 1", "Address": "[email protected]" },
      "Type": "Resource"
    }
  ]
}

Here is some additional context. We are currently rolling out changes to our Mail, calendar and contacts APIs in response to feedback we have received from Preview users. Since some of these changes are breaking changes, and we haven't yet added versioning, you are seeing this issue. Versioning is part of the changes being rolled out to Office 365 and non-backward compatible changes won't be an issue with versioning in place. We are working to update our documentation and the client libraries as soon as possible. In the meantime, we posted an announcement here to give developers a heads up.

Please let me know if you have any questions or need more info.

Thanks,

Venkat

Upvotes: 1

Related Questions