首页 文章

Office365 REST API - 使用附件创建日历事件

提问于
浏览
2

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

我发送POST请求到:

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

我使用以下Authorization标头:

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,以及向附件添加name,size和contentType字段 . 所有这些都给出了相同的结果 - 201响应,以及没有附件创建的事件 .

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

1 回答

  • 3

    我也看到了!我可以在创建事件后发布附件,只是不包含具有初始创建有效负载的附件 .

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

    POST /me/events/{eventid}/attachments
    
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "name": "$(fileName)",
      "contentBytes": "$(base64EncodedString)"
    }
    

    我将与日历上的人员核实,看看为什么它在初始POST期间无法正常工作 .

相关问题