0
votes

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
I'm getting a success status code On success you should receive 202 Accepted. Do you add a bearer access token to the request? - Hamlet Hakobyan
@HamletHakobyan Yes, I am receiving 202 Accepted. I'm adding the bearer access token to the request as part of the GetClient() function which returns the HTTP Client. - Parapraxis
The event isn't canceled, and it isn't removed from my calendar How do you observe that? Have you called GET me/events/{id} after? - Hamlet Hakobyan
@HamletHakobyan I'll try that now. I have the calendar open so that I can watch everything in real time when I run my tests. Everything else (creating a new event, updating an event, deleting events that don't need to be canceled, and getting events) works perfectly. So far I've been getting events at the beginning, but I'll try adding another GET after this is called. - Parapraxis
@HamletHakobyan So, after adding in that extra GET I've found that the event is indeed being canceled/is no longer there. However in my outlook.com calendar itself the event is still present even after reloading the page, and I still have to right manually cancel it in order to delete it/actually send a cancellation message to the attendees. - Parapraxis

1 Answers

0
votes

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