Ray Pendergraph
Ray Pendergraph

Reputation: 458

$orderby with $filter doesn't seem to work as documented

I'm trying to hit the https://graph.microsoft.com/v1.0/users endpoint and I'm running into a problem with pretty much any combination of $filter and $orderby. The docs about this combination say:

  1. Properties that appear in $orderby must also appear in $filter.
  2. Properties that appear in $orderby are in the same order as in $filter.
  3. Properties that are present in $orderby appear in $filter before any properties that aren't.

which seems to suggest this is possible. These aren't the real query I'm trying to run but these are the minimum representation. Some examples:

$orderby=displayName&$filter=displayName%20eq%20Miriam
$orderby=displayName&$filter=startswith(displayName,'M')
$orderby=displayName&$filter=startsWith(displayName,'M')&$select=displayName

but I always get the error:

"code": "Request_UnsupportedQuery",
"message": "Sorting not supported for current query."

Am I doing this wrong or is this actually not supported?

Upvotes: 1

Views: 1930

Answers (1)

Shiva Keshav Varma
Shiva Keshav Varma

Reputation: 3595

To achieve this, you need to:

  1. Select the beta endpoint

  2. Add $count=true in the QueryString

  3. Add ConsistencyLevel = eventual to the Request headers

In this way you would be able to achieve this and below is the query you can use

https://graph.microsoft.com/beta/users?$count=true&$filter=startswith(displayName,'M')&$orderby=displayName

Note: APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported.

enter image description here

Please check this Documentation.

Upvotes: 3

Related Questions