Graph List Users API Filters

New Contributor

Hi,

 

I am using this API to list the users - https://graph.microsoft.com/v1.0/users

 

I am trying to filter the users using the display name.

https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'Annexus')

 

I tried to use multiple filters together but got an error - https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'AskAthene')&$filter=startswit...

 

{
    "error": {
        "code""BadRequest",
        "message""Query option '$filter' was specified more than once, but it must be specified at most once.",
        "innerError": {
            "date""2022-07-07T05:32:03",
            "request-id""baff7d09-ae72-42b3-87c7-6fde62020a82",
            "client-request-id""baff7d09-ae72-42b3-87c7-6fde62020a82"
        }
    }
}
 
Is it possible to use multiple values for one filter or do I have to call this API separately for each value I need to filter for ?
 
I need to get all users where display name is in the given list. So, I need to use all names in the list for the filter together.
 
Is this possible ?
2 Replies
The error is because you're adding multiple $filter operators. Simply adjust the filter query within a single $filter operator. Refer to the official documentation if you need examples on how to build more complex filter queries: https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter
In the documentation, there is no example that uses multiple filters.
GET https://graph.microsoft.com/v1.0/users?$filter=startsWith(displayName,'J')

I am still trying to understand dhow we can use multiple filters with the same function - startsWith and use multiple values to match.