无法使用 Office 365 API 创建新事件 [英] Can't create new events with Office 365 API

查看:73
本文介绍了无法使用 Office 365 API 创建新事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Office 365 API 中的日历 REST,并尝试根据以下示例发布事件:http://msdn.microsoft.com/en-us/library/office/dn792114(v=office.15).aspx

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

我得到的回应是

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

当我使用 Avanced Rest Client 发布到 URL https://outlook.office365.com/ews/odata/Me/Events 带有 Content-Type: application/json 并且我使用的是 office365 服务帐户.

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.

我发布的 JSON 是从上面链接中的示例复制的

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"
    }
  ]
}

如果 "@odata.type": "#Microsoft.Exchange.Services.OData.Model.Event""Attendees" 一起被删除,则发布成功.

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.

推荐答案

感谢您的来信,对于给您带来的不便深表歉意!以下是您的请求的修改版本,应该可以工作.我做了两个改变.与会者列表现在包括一个名为 EmailAddress 的类型.我还省略了 @odata.type,因为您不必包含它,并且由于您要发布到集合,因此我们的服务会推断出该类型.邮件、日历和联系人的命名空间已从#Microsoft.Exchange.Services.OData.Model"更新为#Microsoft.OutlookServices",这就是 @odata.type 为您返回错误的原因.

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"
    }
  ]
}

这里有一些额外的上下文.我们目前正在对我们的邮件、日历和联系人 API 进行更改,以响应我们从预览版用户那里收到的反馈.由于其中一些更改是破坏性更改,而且我们尚未添加版本控制,因此您会看到此问题.版本控制是向 Office 365 推出的更改的一部分,非向后兼容的更改不会成为版本控制的问题.我们正在努力尽快更新我们的文档和客户端库.与此同时,我们发布了一个 公告在这里提醒开发者.

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.

谢谢,

文卡特

这篇关于无法使用 Office 365 API 创建新事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆