Office365 REST API-创建带有附件的日历事件 [英] Office365 REST API - Creating a calendar event with attachments
问题描述
我无法使用Office365的Rest API创建带有附件的日历事件.创建没有附件的事件不是问题.尝试使用附件创建事件会创建事件,但不会添加我发送的文件.服务器以201响应码作为响应.
I am unable to create a calendar event with attachments using Office365's Rest API. Creating events without attachments is not a problem. Trying to create events with attachments creates the event, but the files I send are not added. The server responds with a 201 response code.
我正在发送POST请求至:
I am sending a POST request to:
https://graph.microsoft.com/v1.0/me/calendars/$(calendarID)/events
我使用以下授权标头:
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/zh-CN/graph/docs/api-reference/beta/api/calendar_post_events .我的事件遵循事件架构 ,并且附件遵循 fileAttachment架构.
I'm following the documentation at https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/calendar_post_events. My event follows the event schema, and the attachments follow the fileAttachment schema.
我为@ odata.type尝试了不同的值,从请求中删除了hasAttachments,并为附件添加了名称,大小和contentType字段.所有这些都给出相同的结果-201响应,并且创建了一个没有附件的事件.
I have tried different values for @odata.type, removing hasAttachments from the request, as well as adding name, size, and contentType fields to the attachment. All of these give the same result - a 201 response, and an event created without attachments.
任何帮助将不胜感激,谢谢!
Any help would be much appreciated, thanks!
推荐答案
我也看到了!创建事件后,我可以将其发布到事件中,只是不将其包含在初始创建有效内容中.
I see this too! I'm able to post an attachment to the event after it's created, just not include one with the initial create payload.
作为一种解决方法,您可以先创建事件,然后再做
So as a workaround, you can create the event, then do
POST /me/events/{eventid}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "$(fileName)",
"contentBytes": "$(base64EncodedString)"
}
我将就此与日历部门的人员进行核实,以了解为什么它在最初的POST期间无法正常工作.
I'll check with the calendaring folks on this to see why it's not working during the initial POST.
这篇关于Office365 REST API-创建带有附件的日历事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!