Finding mail messages with no categories set?

Ward Horsfall 101 Reputation points
2022-06-23T19:25:36.947+00:00

Hi

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.

Thanks
Ward

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
    2022-06-24T00:11:00.263+00:00

    You can do it using and Advanced query with filter https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http eg

    $filter=NOT(categories/any())&count=true  
    

    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