Incorrect @odata.count when using $count=true on /messages endpoint without specifying a folder

GM 136 Reputation points
2022-07-27T22:51:42.583+00:00

It appears that when using https://graph.microsoft.com/v1.0/me/messages?$count=true the @odata.count filed has a value that does not correspond to the messages returned but is instead higher (there is no paging of results since there are no messages).

{  
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('6ac48f8b-a7df-48f8-abf4-dde72afd7c56')/messages",  
    "@odata.count": 148,  
    "value": []  
}  

The same issue does not exist if the query is scoped to https://graph.microsoft.com/v1.0/me/mailFolders/<folder id>/messages?$count=true. In this case, @odata.count matches the number of values returned.

{  
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('6ac48f8b-a7df-48f8-abf4-dde72afd7c56')/mailFolders('inbox')/messages",  
    "@odata.count": 0,  
    "value": []  
}  

I've also tried this when messages are present, but the number continues to be off.

It is interesting to note that this only happens after all messages for the user got deleted from their Inbox and then from Deleted Items. The number by which @odata.count value is off in the query for all messages appears to be constant after this.

I wonder if this is a bug or for some reason $count is not supported when making a /messages query without specifying a folder.

Thanks you!

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AtulThorat-MSFT 391 Reputation points
    2022-07-28T12:32:47.97+00:00

    Hi @georgimatev-2532,

    Hope you are doing well.

    I tried Graph API endpoint messages as shown below.

    225851-mail-count.png

    Also I checked graph API endpoint messages as shown below.
    225824-mail-folder-count.png

    In my tenant I could able to see correct count for mail items in all mail folder. I am unable to reproduce this issue in my tenant. Could you please verify again count of mail in all mail folder such as "Inbox" , "Sent Items" etc.

    I would recommend you to raise a support case with Microsoft Graph, a Support Engineer will be able to assist you better. You can raise support ticket from admin.microsoft.com.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. GM 136 Reputation points
    2022-07-28T15:43:25.787+00:00

    @AtulThorat-MSFT thanks for taking a look.

    In my testing, I discovered that the issue only occurs once ALL emails for a user were deleted from Inbox and then removed from Deleted Items. At that point, there are no emails in the users Inbox, but the count appears as shown above. The count remains incorrect if emails are restored or new emails arrive in the mailbox.

    The repro steps are a bit convoluted (we discovered this on our Dev tenant where we have tests that do the type of cleanup described) but enough to have us question how we should be using the count.

    I'll also submit a support ticket as you advised.

    Thanks!

    P.S: Some additional testing indicates that the precondition is just empty Inbox. The emails did not have to be purged from Deleted Items.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.