The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Hi @SalesOutlook
I just tested this API locally, and it works well. I can use the client credentials flow to create events for other users. Please note that your MS 365 user must have an MS 365 license.
Additionally, I recommend using the OdataError class to catch exceptions.
try
{
var requestBody = new Event
{
Subject = "Let's go for lunch",
Start = new DateTimeTimeZone
{
DateTime = "2024-08-15T12:00:00",
TimeZone = "Pacific Standard Time",
},
End = new DateTimeTimeZone
{
DateTime = "2024-08-15T14:00:00",
TimeZone = "Pacific Standard Time",
},
};
var result = await graphClient.Users["{user-id}"].Events.PostAsync(requestBody);
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
}
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.