Microsoft graph sdk C#: Create subscription throw error as below expirationDateTime is a required property for subscription creation
Setup of my graph client
// Values from app registration
var clientId = integration.UserName;
var tenantId = integration.TenantId;
var clientSecret = integration.ApiKey;
// using Azure.Identity;
var options = new ClientSecretCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential);
=====
try
{
var webhook = new Subscription
{
ChangeType = "created",
NotificationUrl = notificationURL,
Resource = "me/messages",
ExpirationDateTime = DateTimeOffset.Now.AddMinutes(3500),
ClientState = Guid.NewGuid().ToString(),
LatestSupportedTlsVersion = "v1_2",
};
var webhookDataResult1 = graphClient.Subscriptions.ToPostRequestInformation(webhook);
var webhookDataResult = await graphClient.Subscriptions.PostAsync(webhook);
// Successful creation of the webhook
}
catch (ODataError odataError)
{
Console.WriteLine($"Graph API error response: {odataError.Error.Code}");
Console.WriteLine($"Graph API error response: {odataError.Error.Message}");
}