Filtering on onPremisesSamAccountName is not working

Wayne Gibson 36 Reputation points
2021-10-05T11:36:13.62+00:00

Hi,
just trying the following query:

https://graph.microsoft.com/v1.0/users/?$filter=onPremisesSamAccountName eq 'username'

But it is returning:

{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'onPremisesSamAccountName' of resource 'User'.",
"innerError": {
"date": "2021-10-04T23:26:08",
"request-id": "f7417ed9-c130-458f-b724-0b1fdd29c0f7",
"client-request-id": "742f6e0e-b234-1c3b-ac8e-b9ea290dded8"
}
}
}

Same for beta.

But the following https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0 indicates that filtering is supported Returned only on $select. Supports $filter (eq, ne, NOT, ge, le, in, startsWith).

So just wanted to check if is and there is an error with the query or it's a documentation issue ?

Thanks

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} vote

Answer accepted by question author
  1. Vasil Michev 123.5K Reputation points MVP Volunteer Moderator
    2021-10-05T12:55:27.827+00:00

    You missed the big blue Note:

    Specific usage of $filter and the $search query parameter is supported only when you use the ConsistencyLevel header set to eventual and $count. For more information, see Advanced query capabilities on Azure AD directory objects.

    The following article lists each individual attribute you can use $filter against, as well as the ones that require ConsistencyLevel and $count=true. https://learn.microsoft.com/en-us/graph/aad-advanced-queries
    Adding those will result in a working query.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wayne Gibson 36 Reputation points
    2021-10-05T13:07:50.57+00:00

    Thanks, how did I miss that....

    GET https://graph.microsoft.com/v1.0/users/?$filter=onPremisesSamAccountName eq 'username'&$count=true
    Header ConsistencyLevel=eventual

    137715-image.png

    However note that it also works without the header, only needs the $count=true

    2 people found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.