Filtering on onPremisesSamAccountName is not working

Wayne Gibson 31 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 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
    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wayne Gibson 31 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

    1 person found this answer helpful.