I am trying to filter out Guest
users in my Graph query. Since the ne
comparison operator is not supported I was trying $filter=userType eq 'Member' or userType eq null
instead. That fails too though. Any known workarounds to list users with null
as userType
?
Without that I need to download about a million rows each time and throw 4 out of 5 away on the client side, which is pretty slow and wasteful.
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'userType' of resource 'User'.",
"innerError": {
"request-id": "411f7927-c3af-4042-a619-eee1c88971a0",
"date": "2018-03-17T18:28:35"
}
}
As a general rule of thumb, userType
should be either Member
or Guest
. The exception to this is when you're syncing an on-prem Active Directory. Since userType
is an Azure AD property, the value for a synced user will be null
.
If you can safely assume that your on-prem users are not guests, you can filter Azure AD user's based on if they're synced or cloud-native. You do this by looking at the onPremisesSyncEnabled
property. For synced users, this will be true
, for cloud-native users it will be null
.
If you combine this with the userType
property, you can effectively retrieve only non-guest users using the following $filter
:
$filter=onPremisesSyncEnabled eq true OR userType eq 'Member'
You can also avoid this entirely if you Enable synchronization of UserType in Azure AD Connect.