0

My intention is to build a Machine Learning program that will give a recommendation for archiving email item by reading all previous email history.

For that, I am trying to read all the email item from:

https://graph.microsoft.com/beta/me/messages

First I am getting the total number of email items in my account using /messages?$count=true which returns 1881 as the result.

Then I am trying to get all the 1881 item using:

https://graph.microsoft.com/beta/me/messages?$top=1881

But the problem is that returns 976 email items. Where are the rest of the email item? How I can find them?

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Kawsar Hamid
  • 514
  • 3
  • 13

1 Answers1

4

Are you getting a @odata:nextLink property in your response?

If that's the case, you might need to send another request with a skiptoken parameter. It should contain a value from the @odata:nextLink response property.

On the "paging" documentation page - https://developer.microsoft.com/en-us/graph/docs/concepts/paging - it is specified that different APIs have different max page size. It's possible that the endpoint for fetching emails does not support a page size of 1881. In that case, you might need to access a second page of the results.

Another suggestion is to replace beta endpoint with the V1 API call because me/messages is available there also - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_messages

Wayne Yang
  • 9,016
  • 2
  • 20
  • 40
shtrule
  • 658
  • 10
  • 23
  • it doesn't have any next link and I tried using the V1 API. The results is same. – Kawsar Hamid Jun 05 '18 at 22:36
  • What kind of permissions are you using - Mail.Read application permission with admin consent or delegated permissions that does not require admin consent? – shtrule Jun 06 '18 at 15:31
  • offline_access User.Read Mail.Read Mail.ReadWrite – Kawsar Hamid Jun 07 '18 at 00:15
  • That seems alright to me. Even though it shouldn't be a problem, I would try to fetch messages with a smaller $top parameter, e.g. $top=100 because some of the endpoints act weird if that parameter exceeds max page size. Can you also confirm that the mailbox actually contains 1881 items? Or can you spot if specific mail folders are excluded from the response? – shtrule Jun 08 '18 at 13:07
  • I can try using $top=100. Yes I tried $count=true and response was 1881. – Kawsar Hamid Jun 08 '18 at 15:03
  • @KaiserNayan I'm also facing the same issue, there might be an issue with the API, if you check [this](https://github.com/microsoftgraph/microsoft-graph-docs/issues/2153) thread, it seems the messages endpoint doesn't work reliably. – Gokulnath K Jun 15 '18 at 15:10