Mar 11 2021 12:12 PM
So I am using the latest Microsoft.Graph NuGet package in a VS 2019 project. Looking to create a new calendar event. The API request doesn't even send out, although if I place the same JSON request body in the Graph Explorer web page it returns a successful response.
Here is a snippet of my method.
var clientId = "...";
var tenantId = "...";
var clientSecret = "...";
var newEvent = new Event();
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
ClientCredentialProvider authenticationProvider = new
ClientCredentialProvider(confidentialClientApplication);
HttpClient httpClient = GraphClientFactory.Create(authenticationProvider);
// Build my newEvent here...
// This requestBody is identical to the one that works in the online Graph Explorer.
var requestBody = JsonConvert.SerializeObject(newEvent);
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post,
string.Format("users/{0}/calendar/events", upn));
var content = new System.Net.Http.StringContent(requestBody, Encoding.UTF8, "application/json");
requestMessage.Content = content;
Console.WriteLine(requestBody);
// This is where the program doesn't throw an exception, but doesn't perform the API call either.
HttpResponseMessage response = await
httpClient.SendAsync(requestMessage).ConfigureAwait(false);
var jsonResponse = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var jObject = JObject.Parse(jsonResponse);
var id = (string)jObject["id"];
Any suggestions on what I can try? I can see that the URI is calling the v1.0, which worked for similar methods I have in this project that I used maybe 1-2 years ago. Spinning my wheels for sure!
Mar 11 2021 12:44 PM
Mar 12 2021 07:18 AM
Mar 12 2021 09:11 AM
SolutionMar 12 2021 09:11 AM
Solution