question

WayneGibson-9279 avatar image
0 Votes"
WayneGibson-9279 asked WayneGibson-9279 answered

Filtering on onPremisesSamAccountName is not working

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://docs.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-sdkmicrosoft-graph-usersazure-ad-user-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

michev avatar image
1 Vote"
michev answered

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://docs.microsoft.com/en-us/graph/aad-advanced-queries
Adding those will result in a working query.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneGibson-9279 avatar image
0 Votes"
WayneGibson-9279 answered

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



image.png (22.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.