While I was exploring the Microsoft Graph REST API and working with Calendar Events:


the next logical step was to delete an event and nothing could be easier!
As with everything in the Graph REST API, everything is driven by an ‘ID’. This is the PK of everything (e-mails, contacts, users, events, …). Hence, the critical aspect to being able to delete anything, including an event, is to first identify the events ‘ID’. Once you have that, then it is a simply URL call and it is done.
Finding An Events ‘ID’
Finding the ID can be done in 2 ways:
- At the time of creation, the id is returned as part of the HTTP Response, so you could extract it at that point in time.
- You could use one of the routines I previously provided in my “Searching Calendar Events With The Microsoft Graph API” (link is above) to find the event and get its’ Id.
Deleting An Event
After checking the documentation, it didn’t take me long to put together a simple procedure:
'---------------------------------------------------------------------------------------
' Procedure : Outlook_Calendar_DeleteEvent
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Delete the specified event
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
' References: https://learn.microsoft.com/en-us/graph/api/event-delete?view=graph-rest-1.0&tabs=http
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sEventId : The Events Id
'
' Usage:
' ~~~~~~
' ? Outlook_Calendar_DeleteEvent("AQMkADhmYTcwNWQ3LTVmYjYtNGZiYS1iMTA4L...==")
' Returns -> True
'
' Revision History:
' Rev Date(yyyy-mm-dd) Description
' **************************************************************************************
' 1 2024-05-30
'---------------------------------------------------------------------------------------
Public Function Outlook_Calendar_DeleteEvent(ByVal sEventId As String) As Boolean
On Error GoTo Error_Handler
Dim sContentType As String
Dim sURL As String
If OAuth2.access_token = "" Then OAuth2_StoredCredentials_Load 'Make sure we have credential before proceeding
If OAuth2_CheckToken = False Then DoCmd.OpenForm sAuthenticationForm, , , , , acDialog 'Force authentication if req'd
sContentType = "application/json"
sURL = "https://graph.microsoft.com/v1.0/me/events/" & sEventId
'Debug.Print sURL
'Call HTTP_SendRequest(sURL, "DELETE", sContentType, , True)
Call HTTPServer_SendRequest(sURL, "DELETE", sContentType, , True)
'Call WinHttp_SendRequest(sURL, "DELETE", sContentType, , True)
If lHTTP_Status = 204 Then
Outlook_Calendar_DeleteEvent = True
Debug.Print sHTTP_ResponseText
Else
Debug.Print lHTTP_Status
Debug.Print "--------"
Debug.Print sHTTP_ResponseText
End If
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: Outlook_Calendar_DeleteEvent" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Function
where I can now simply delete an event by doing
? Outlook_Calendar_DeleteEvent("AQMkADhmYTcwNWQ3LTVmYjYtNGZiYS1iMTA4L...==")