Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Sorting not supported for current query." error when sorting List members API

I keep getting the above error when try to sort the list on displayName, however sorting is clearly supported according the example below: https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=csharp#request-3

I tried adding ConsistencyLevel headers and count query param with no luck.

var users = await GraphHelper.client.Users
    .Request() //new List<QueryOption>() { new QueryOption("$count","true") }
    .Header("ConsistencyLevel", "eventual")
    .Filter($"accountEnabled eq true and extension_{AppConfig.variable["B2C:ExtensionId"]}_BankId eq '{bankId}'")
    .OrderBy("displayName")
    .Select($"id,displayName,identities,extension_{AppConfig.variable["B2C:ExtensionId"]}_BankId").GetAsync();

enter image description here

Same query works in graph explorer but not in the REST API.

enter image description here

like image 665
Chris Gunawardena Avatar asked Aug 31 '26 06:08

Chris Gunawardena


1 Answers

I suspect that you are seeing this discrepancy because of incorrect setup in POSTMAN and code.

You can setup POSTMAN by following this step-by-step guide. A quick glance of steps is below:

  • Registering the Azure AD App
  • Get admin consent for the app
  • Get access token using the app
  • Make Microsoft Graph API call using the access token as bearer token

Similarly, please check similar setup of C# code as well.


Edit:

It seems there are some rules that we need to follow while using filter and orderby:

enter image description here

Hence, when I followed the rules and ran https://graph.microsoft.com/beta/users?$count=true&$filter=startsWith(displayName,'B')&$orderby=displayName desc query, it works:

enter image description here

like image 90
Harshita Singh Avatar answered Sep 02 '26 22:09

Harshita Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!