Search code examples
c#restoutlookoutlook-restapi

Update event with outlook rest api fails with Method Not Allowed


I have an application that uses the outlook REST API for creating events on the user's calendar. The creation of the event works perfectly, but once I tried to to exactly as this post indicates, I get 405 Method Not Allowed.

the error details are as follow:

{"error":{"code":"ErrorInvalidRequest","message":"The OData request is not supported."}}

here's a part of my code:

    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post, new Uri("https://outlook.office365.com/api/v1.0/me/events/"+meeting.OutlookEventId));

    var auth = "Bearer " + token;
    request.Headers.Add("Accept", "application/json");
    request.Headers.Add("Authorization", auth);

    var converters = new List<JsonConverter>();
    converters.Add(new MyStringEnumConverter());

    var createResponse = @"{
      'Location': {
        'DisplayName': 'Your office'
      }
    }";

    request.Content = new StringContent(createResponse);
    request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var response = await client.SendAsync(request);

I have the user token sotred on the "token" variable, as well as the outlook event Id on the "meeting.OutlookEventId" variable.

Any ideas?

Thank you very much!


Solution

  • I feel like a total fool...

    I was sending a POST when this request required a PATCH

    I just replaced

    HttpMethod.Post
    

    for

    new HttpMethod("PATCH")