Error accepting attendees meeting invite though Microsoft Graph

Sanjeev 11 Reputation points
2021-04-06T11:38:44.07+00:00

I am trying to accept the meeting using Service Principal who has Admin Consent on Calendar.Read, Calendar.ReadWrite permission using MS Graph, so that the invited users don't have to accept the meeting. But i keep getting object was not found error.

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;    

using (var httpClient = new HttpClient())
{
    string resultjson = "";
    string attendeeUPN = "john@test.com";  //user who has the meeting event
    string eventId = CreateEvent(attendeeUPN);  //this will create new event
    string authToken = GetToken();  //accessToken is generated using servicePrincipal which has Admin Consent on Calendar.Read, Calendars.ReadWrite permissions both on Delegated and Application Type

    EventAcceptRequestBody eventAcceptRequestBody = new EventAcceptRequestBody();
    eventAcceptRequestBody.SendResponse = false;    
    string jsonBody = JsonConvert.SerializeObject(eventAcceptRequestBody);

    string url = $"https://graph.microsoft.com/v1.0/users/{attendeeUPN}/calendar/events/{eventId}/accept"
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
    var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");   

    HttpResponseMessage response = httpClient.PostAsync(url, content).Result;
    resultjson = await response.Content.ReadAsStringAsync();
    return resultjson;
}

The event gets created and when the code runs to accept, i get this error message:

{"error":{"code":"ErrorItemNotFound","message":"The specified object was not found in the store."}}

Based on the documentation i read, everyone suggests to use service principal which have both Calendar.Read and Calendar.ReadWrite permissions (with Admin consent) to be able to do this, however i am still getting the object not found error.

Any suggestions?
Sanjeev

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,723 questions
{count} votes