Filtering on onPremisesSamAccountName is not working

Wayne Gibson 31 Reputation points

just trying the following query:$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 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 ?


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,431 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,614 questions
0 comments No comments
{count} vote

Accepted answer
  1. Vasil Michev 100.2K Reputation points MVP

    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.
    Adding those will result in a working query.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wayne Gibson 31 Reputation points

    Thanks, how did I miss that....

    GET$filter=onPremisesSamAccountName eq 'username'&$count=true
    Header ConsistencyLevel=eventual


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

    1 person found this answer helpful.