Graph API not working - ( Unhandled exception. Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and the error registered for this code failed to deserialize: 500 )
Using correct credentials as clientid , tenantid , clientsecret key
some times unable to read mail data and getting exception as below ------------------>
Unhandled exception. Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and the error registered for this code failed to deserialize: 500
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponseAsync(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsyncModelType
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsyncModelType
at Microsoft.Graph.Users.Item.MailFolders.Item.Messages.MessagesRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)
at Program.Main(String[] args) in C:\Users\avis\Desktop\email\GraphMailReader\Program.cs:line 22
at Program.<Main>(String[] args)
BELOW CODE USED ------------------------------------------------->
var scopes = new[] { "https://graph.microsoft.com/.default" };
var credential = new ClientSecretCredential(emailConfig.OutlookTenantId, emailConfig.OutlookClientId, emailConfig.OutlookClientSecret);
var graphClient = new GraphServiceClient(credential, scopes);
try
{
var messages = await graphClient.Users[emailConfig.incomingmailid].MailFolders["Inbox"].Messages
.GetAsync(req =>
{
req.QueryParameters.Top = 1;
req.QueryParameters.Select = new[] { "subject", "from", "receivedDateTime", "body", "bodyPreview", "internetMessageId", "internetMessageHeaders" };
req.QueryParameters.Orderby = new[] { "receivedDateTime desc" };
});