0

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);
        }
    }
Parapraxis
  • 3
  • 1
  • 5
  • `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 May 23 '17 at 14:18
  • @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 May 23 '17 at 14:23
  • `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 May 23 '17 at 14:27
  • @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 May 23 '17 at 14:32
  • 1
    @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 May 23 '17 at 14:40
  • Can you check by another client? – Hamlet Hakobyan May 23 '17 at 14:42
  • @HamletHakobyan I just tried the outlook app on my phone, as well as the stock android calendar app. Both showed the event as still present and needing to be manually canceled. I also do not get a cancellation notice until I manually cancel the event. – Parapraxis May 23 '17 at 14:52
  • Seems [this](https://github.com/microsoftgraph/microsoft-graph-docs/issues) is your way to go. – Hamlet Hakobyan May 23 '17 at 14:56
  • Thanks for trying to help at least, much appreciated! I'll open an issue and see what I can get figured out. – Parapraxis May 23 '17 at 14:59

1 Answers1

0

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

Parapraxis
  • 3
  • 1
  • 5