4
votes

I am trying the following request using microsoft graph:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime lt 2016-03-07T16:55:39Z

In this example I am trying to retrieve all emails that were received prior to the supplied date (which is actually today).

However, the Microsoft Graph API returns only one message for this request, which is the first message I ever received on my account, despite there being many other emails which fit this criteria. Note that le also suffers the same problem.

I assume this is a bug and am raising it here for visibility, but any suggestions of workarounds or problems with my example would be appreciated.

2
That exact query (literally) works just fine for me. Are you authenticating as an Office 365 user (i.e. Exchange Online mailbox) or a Microsoft Account (i.e. Outlook.com mailbox)? Did you try this in Graph Explorer (graphexplorer2.azurewebsites.net) or with your own code? - Philippe Signoret
Please share the value of request-id and Date headers in the API response. - Sriram Dhanasekaran-MSFT
@PhilippeSignoret I am using the Graph Explorer as an Office 365 user. Interestingly, colleagues I have asked to try this also experience the same issue. - eggm0n
@SriramDhanasekaran-MSFT request-id is b2211250-bfc4-42be-9bbc-73209cf2715d. I can't seem to see a Date header using the Graph Explorer. - eggm0n

2 Answers

2
votes

I was able to solve this problem by sorting the results by receivedDateTime DESC.

Try this, worked for me:

me/messages?$filter=receivedDateTime lt 2016-03-07T16:55:39Z&$orderby=receivedDateTime desc
2
votes

What you're describing is a known issue. What's happening is:

Due to some implementation details, Messages, Events, Contacts, and other item types can all live together in a folder. Since the Messages collection is only returning Messages, we have to skip over the other items. Currently, you will see when we skip over items as gaps. A page of 10 items with less than 10 items populated (but still containing a @odata.nextLink) is how you would identify this.

Now this won't typically happen for most actual mail folders (for example https://graph.microsoft.com/v1.0/me/MailFolders/Inbox/messages), but you are querying https://graph.microsoft.com/v1.0/me/messages collection, which is scoping the query to your whole mailbox. The net result is that there can be lots of items that satisfy your criteria that are not messages.

We are working on making this experience better, but for the time being, you should be able to page through @odata.nextLinks until you get all of the data you're looking for.