Home > OS >  Microsoft Graph filter is getting an error of Unsupported Query
Microsoft Graph filter is getting an error of Unsupported Query

Time:01-17

I'm trying to get all users not in a specific domain. I'm using a filter directly from Microsoft's Graph documentation here. However, Graph returns an Unsupported Query error. I'm stumped.

Query:

            var usersPage = await _graphClient
            .Users
            .Request()
            .Filter("not(endsWith(mail, 'excludeddomain.com'))")
            .GetAsync();

CodePudding user response:

I figured it out. Using some operators such as 'ne' or 'not' require advanced query capabilities. To get the advanced query capabilities you must "must add the ConsistencyLevel header set to eventual and use the $count=true query string."

Correct syntax:

           var usersPage = await _graphClient
            .Users
            .Request(new Option[] { new QueryOption("$count", "true") })
            .Header("ConsistencyLevel", "eventual")
            .Filter("not(endsWith(mail, 'excludeddomain.com'))")
            .GetAsync();
  • Related