Search code examples
outlookmicrosoft-graph-apirecurring-events

I'd like to cancel a single event from recurring events using the Microsoft Graph API


I have created a recurring event from December 3rd to 6th using the graph API, which repeats daily. I'd like to cancel a single event on December 4th. How can I achieve this? I fetched the event ID for the particular day. If I cancel an event using the event ID, all the events will be removed from the Outlook calendar. I don't want that. I want to remove only certain events from the Outlook calendar.

This is one of the event responses.

{
            "@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,
            "[email protected]": "https://graph.microsoft.com/v1.0/users('@domail.com')/calendars('AAAA...=')/$ref",
            "[email protected]": "https://graph.microsoft.com/v1.0/users('@domail.com')/calendars('AAA...')"
        }

I tried to cancel a single event using ID. All events are removing from the calendar.


Solution

  • Find the instances using following API

    GET /me/events/{id}/instances?startDateTime={start_datetime}&endDateTime={end_datetime}
    

    then take the occurrence (instance id)

    delete the specific occurence (instance)

     DELETE  - https://graph.microsoft.com/v1.0/me/events/{instance-id}