Error accepting attendees meeting invite though Microsoft Graph
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