Is it possible to cancel an event using Microsoft Graph?

2.5k Views Asked by At

I'm trying to write a simple api in C# that will be used to, among other things, delete events from a user's calendar using the Graph api.

The problem I've run into is that I can't delete events that need to be canceled, obviously because they need to be canceled. However, I can't figure out how to write a function to actually CANCEL these events. I'm currently using https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/event_cancel to try and cancel an event, and I'm getting a success status code... but nothing happens. The event isn't canceled, and it isn't removed from my calendar.

Any suggestions or advice are greatly appreciated. My code for canceling an event is below.

   public async void CancelAppointment(string eventId)
    {
        try
        {
            var client = GetHttpClient();
            Uri targetEndpoint = new Uri("https://graph.microsoft.com/beta/me/events/" + eventId + "/cancel");
            string postBody = "{" +
                              "\"Comment\": \"Appointment canceled.\"" +
                              "}";
            var body = new StringContent(postBody, System.Text.Encoding.UTF8, "application/json");

            var response = await client.PostAsync(targetEndpoint, body);
            Console.WriteLine(response.StatusCode);

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Canceled appointment with Id: " + eventId);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Could not cancel appointment " + eventId + " " + e.Message);
        }
    }
1

There are 1 best solutions below

0
On

This appears to have been fixed. Events are now canceling properly with no changes made to my own code.