Can't create new events with Office 365 API

隐身守侯 提交于 2019-12-12 02:02:41

问题


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": "alexd@contoso.com",
      "Type": "Required"
    },
    {
      "Name": "Anne Wallace",
      "Address": "annew@contoso.com",
      "Type": "Optional"
    },
    {
      "Name": "Conference Room 1",
      "Address": "conf1@contoso.com",
      "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.


回答1:


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": "alexd@contoso.com" },
      "Type": "Required"
    },
    {
      "EmailAddress": { "Name": "Anne Wallace", "Address": "annew@contoso.com"},
      "Type": "Optional"
    },
    {
      "EmailAddress": { "Name": "Conference Room 1", "Address": "conf1@contoso.com" },
      "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



来源:https://stackoverflow.com/questions/26399352/cant-create-new-events-with-office-365-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!