我无法使用 Office365 的 Rest API 创建带有附件的日历事件。创建没有附件的事件不是问题。尝试创建带有附件的事件会创建事件,但不会添加我发送的文件。服务器以 201 响应代码响应。

我正在向以下地址发送 POST 请求:

https://graph.microsoft.com/v1.0/me/calendars/$(calendarID)/events

我使用以下授权 header :
Authorization: Bearer $(tokenString)

请求有效载荷:
{
  "start": {
    "dateTime": "2017-09-27T20:00:00.000",
    "timeZone": "UTC"
  },
  "end": {
    "dateTime": "2017-09-27T21:00:00.000",
    "timeZone": "UTC"
  },
  "attendees": [
    {
      "emailAddress": {
        "address": "person@example.com"
      },
      "type": "Required"
    }
  ],
  "subject": "Example subject",
  "body": {
    "content": "Example content",
    "contentType": "Text"
  },
  "hasAttachments": true,
  "sensitivity": "Normal",
  "attachments": [
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "name": "$(fileName)",
      "contentBytes": "$(base64EncodedString)"
    }
  ]
}

我正在关注 https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/calendar_post_events 的文档。我的事件遵循 event schema ,附件遵循 fileAttachment schema

我为@odata.type 尝试了不同的值,从请求中删除了 hasAttachments,并向附件添加了名称、大小和 contentType 字段。所有这些都给出了相同的结果 - 201 响应和创建的没有附件的事件。

任何帮助将不胜感激,谢谢!

最佳答案

我也看到这个!我可以在创建事件后发布一个附件,只是不包括带有初始创建负载的附件。

因此,作为一种解决方法,您可以创建事件,然后执行

POST /me/events/{eventid}/attachments

{
  "@odata.type": "#microsoft.graph.fileAttachment",
  "name": "$(fileName)",
  "contentBytes": "$(base64EncodedString)"
}

我将与日历人员核实这一点,看看为什么它在初始 POST 期间不起作用。

关于Office365 REST API - 创建带有附件的日历事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46438302/

10-14 06:16