‎Filtering Users On The Basis Of Domains‎ Using Graph API

Dev User 1 Reputation point
2020-06-19T13:06:15.49+00:00

Hello. I am trying to get the users of a particular domain via the users endpoint.

https://graph.microsoft.com/v1.0/users.

I have tried using the endswith filter on the userPrincipalName in the following manner:

https://graph.microsoft.com/v1.0/users?$filter=endswith(userPrincipalName,'domain.com')

but it returns Request_UnsupportedQuery

Could anyone please help me out on what filters need to be used to restrict the result set on the said criteria

OR

if there is an entirely different endpoint to do this.

Thanks. :)

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,784 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,665 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,311 Reputation points
    2020-06-19T15:09:36.917+00:00

    @DevUser-4116 Unfortunately, the $filter operators doesn't include endswith and contains as of now. The supported $filter parameters are listed here. In the given parameters, I don't see any parameter that can help filtering based on domain name in the UPN.

    There is an active feedback regarding this feature here:
    https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/36040288-useful-user-endpoint-filtering. Please vote for it as this is monitored by the product team.

    If you just want to get a list of users with specific domain name in UPN suffix, you can use below PowerShell Cmdlet.

    Get-AzureADUser | Where-Object {$_.UserPrincipalName -like '@domain.name'}


    Please do not forget to "Accept the answer" wherever the information provided helps you. This will help others in the community as well.

    1 person found this answer helpful.

  2. Lonneman, Shane 6 Reputation points
    2020-08-04T13:36:20.48+00:00

    You can use the beta endpoint for the Microsoft Graph like below to get what you need.

    https://graph.microsoft.com/beta/users?$count=true&$filter=endswith(userPrincipalName, 'some domain name')

    You have to include the Request Header of ConsistencyLevel=eventual in your query.

    1 person found this answer helpful.
    0 comments No comments