Lucien P
Lucien P

Reputation: 85

How can I get Emails through Microsoft Graph from the last hour?

I would like to get emails for a user from the last hour. This is the code I tried:

DateTime Object:

DateTime filter = new DateTime();
filter = DateTime.UtcNow.AddHours(-1);

Call to Graph:

await graphClient.Users[broker.Id].MailFolders.SentItems.Messages.Request().Filter(string.Format("SentDateTime ge '{0}'", filter.ToString("yyyy-MM-ddTHH:mm:ssZ"))).GetAsync();

I get a Microsoft.Graph.ServiceException:

A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.String' for operator kind 'GreaterThanOrEqual'.

How can I fix this ?

Upvotes: 0

Views: 1223

Answers (1)

Shawn Tabrizi
Shawn Tabrizi

Reputation: 12434

It seems like you want to integrate delta queries to be able to query a user's mail, and then the next time query all the new mail that has some to that user since the last query.

We have documentation that shows just how to do that here: Get incremental changes to messages in a folder

I know this does not address your main question, but I hope this helps!

Upvotes: 1

Related Questions