@odata.count does not match actual number of email messages retrieved

Copper Contributor

I have been using Graph API to read messages from a selected mailbox like below.


$url = https://graph.microsoft.com/v1.0/users/email address removed for privacy reasons/messages?filter=((ReceivedDateTime ge 2022-12-22T20:00:00Z) and (receivedDateTime le 2022-12-23T09:00:00Z))&count=true
$Messages = Invoke-RestMethod -Headers @{Authorization = "Bearer $($ConnectGraph.access_token)"} -ContentType application/json -Uri $URL -Method Get


I assume that $Messages.'@odata.count' will return the count of messages fetched.
I then use a loop to retrieve the actual messages making use of $messages.value and taking note of the presence of $messages.'@odata.nextLink'

My finding is:
1) usually $Messages.'@odata.count' is greater than the actual number of messages retrieved.
2) sometimes the 2x counts matched
3) The actual messages (not just count) retrieved is 100% the same as the search result by using Advanced Find in Outlook.

Does anyone have similar experience?

2 Replies
The @odata.count will reflect the total number of messages within the mailbox, matching the current query, whereas the results you are getting are paginated. Thus @odata.count will always be greater or equal to the actual number of messages within the reply. In effect, it represents the total number of entries you will get after you follow all the nextLink queries.

Thanks Vasil for your response.
BTW I really appreciate all your contributions to the O365 community.

As far as this thread goes, maybe I did not express myself correctly.
I am aware that @odata.count contains the total number of messages that should be returned.
However, as I fetch each page (usually 10 items except the last fetch) of messages (based on presence of @odata.nextLink, sometimes I found out that the total messages fetched is less than  the @odata.count.