如何通过Microsoft Graph API取消系列日历中的单个事件
解决Microsoft Graph API删除重复事件单个实例的问题
我通过Microsoft Graph API创建了一个12月3日至6日的每日重复系列事件,希望取消12月4日的单个事件。获取该日期事件的ID后,使用此ID取消时删除了整个系列,仅需移除指定单一日历事件。以下是事件响应示例:
{"@odata.etag": "W/\"/pFxeQaSBUSIyPknbgIPTwABkNrf9g==\"", "id": "AAMkAD......", "createdDateTime": "2023-11-27T05:12:58.3658139Z", "lastModifiedDateTime": "2023-11-27T05:12:59.3662862Z", "changeKey": "/pFxeQaSBUSIyPknbgIPTwABkNrf9g==", "categories": [], "transactionId": null, "originalStartTimeZone": "UTC", "originalEndTimeZone": "UTC", "iCalUId": "040000008200E00074C5B7101A82E0080000000099BAD962F020DA010000000000000000100000003B2078C81680824F805BFF2B2403FE5F", "reminderMinutesBeforeStart": 15, "isReminderOn": true, "hasAttachments": false, "subject": "EventTest Friday", "bodyPreview": "Does EventTest work for you?", "importance": "normal", "sensitivity": "normal", "isAllDay": false, "isCancelled": false, "isOrganizer": true, "responseRequested": true, "seriesMasterId": null, "showAs": "busy", "type": "seriesMaster", "webLink": "https://outlook.office365.com/owa/?itemid=AAMkADQwMWM1Yjd&exvsurl=1&path=/calendar/item", "onlineMeetingUrl": null, "isOnlineMeeting": false, "onlineMeetingProvider": "unknown", "allowNewTimeProposals": true, "occurrenceId": null, "isDraft": false, "hideAttendees": false, "responseStatus": {"response": "organizer", "time": "0001-01-01T00:00:00Z"}, "body": {"contentType": "html", "content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>\r\nDoes EventTest work for you?\r\n</body>\r\n</html>\r\n"}, "start": {"dateTime": "2017-12-03T16:00:00.0000000", "timeZone": "UTC"}, "end": {"dateTime": "2017-12-03T17:00:00.0000000", "timeZone": "UTC"}, "location": {"displayName": "", "locationType": "default", "uniqueId": "", "uniqueIdType": "private"}, "locations": [{"displayName": "", "locationType": "default", "uniqueId": "", "uniqueIdType": "private"}], "recurrence": {"pattern": {"type": "daily", "interval": 1, "month": 0, "dayOfMonth": 0, "firstDayOfWeek": "sunday", "index": "first"}, "range": {"type": "endDate", "startDate": "2017-12-03", "endDate": "2017-12-06", "recurrenceTimeZone": "UTC", "numberOfOccurrences": 0}}, "attendees": [{"type": "required", "status": {"response": "none", "time": "0001-01-01T00:00:00Z"}, "emailAddress": {"name": "", "address": ""}}], "organizer": {"emailAddress": {"name": "", "address": ""}}, "onlineMeeting": null, "calendar@odata.associationLink": "https://graph.microsoft.com/v1.0/users('@domail.com')/calendars('AAAA...=')/$ref", "calendar@odata.navigationLink": "https://graph.microsoft.com/v1.0/users('@domail.com')/calendars('AAA...')"}
问题原因
你之前删除整个系列的核心原因是:获取的ID属于系列主事件(seriesMaster),从响应中的type: "seriesMaster"可确认。直接删除系列主事件会移除整个重复事件系列,而非单个实例。
解决方案
方法一:获取单个实例ID后删除
- 获取目标日期的事件实例
调用Graph API的occurrences端点,筛选出12月4日的事件实例:
GET /me/events/{seriesMasterId}/occurrences?$filter=start/dateTime ge '2017-12-04T00:00:00Z' and start/dateTime lt '2017-12-05T00:00:00Z'
将{seriesMasterId}替换为你已有的系列主事件ID,返回结果中会包含12月4日实例的专属id(此ID对应单个事件,而非系列主)。
- 删除单个实例
使用获取到的实例ID调用删除接口:
DELETE /me/events/{occurrenceId}
此操作仅删除指定日期的单个事件,不会影响其他重复实例。
方法二:直接通过系列主ID+实例时间删除
无需单独获取实例ID,可直接在删除请求中指定目标实例的UTC开始时间(需与事件原始开始时间完全匹配):
DELETE /me/events/{seriesMasterId}?occurrenceDateTime=2017-12-04T16:00:00Z
将{seriesMasterId}替换为系列主事件ID,occurrenceDateTime的值替换为目标实例的UTC开始时间(示例中为2017-12-04T16:00:00Z)。
内容的提问来源于stack exchange,提问作者Vamshi
相关产品推荐
相关产品推荐

