Finding mail messages with no categories set?

Ward Horsfall 101 Reputation points


Is there any way I can do the following:

  1. Using the $filter option only find emails that have no categories set.
  2. Using the $search option only search for emails that have no categories set.


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,937 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,421 Reputation points

    You can do it using and Advanced query with filter eg


    or with the Graph SDK

                var queryOptions = new List<QueryOption>()  
                    new QueryOption("$count", "true")  
                var uncatMessages = graphClient.Me.MailFolders["Inbox"].Messages.Request(queryOptions)  
                    .Header("ConsistencyLevel", "eventual").Filter("NOT(categories/any())").GetAsync().GetAwaiter().GetResult();  
    1. With Search that uses Content index's and KQL so AFAIK you can't search for a null value in a content Index or for the number of values of property in a Index, you could use 'not' in KQL to find message that don't have a particular category value set.
    0 comments No comments