2
votes

I keep getting the above error when try to sort the list on displayName, however sorting is clearly supported according the example below: https://docs.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

2
Do you use beta or v1.0 endpoint?user2250152
Have you tested it in Graph Explorer or POSTMAN?Shiva Keshav Varma
A guess -- order by is throwing exception as extension property is used in filter clause?user1672994
@Shiva-MSFTIdentity I tried in Graph Explorer https://graph.microsoft.com/v1.0/users?$search="displayName:wa"&$orderby=displayName works but https://graph.microsoft.com/v1.0/users?$filter=accountEnabled%20eq%20true&$orderby=displayName returns Request_UnsupportedQueryChris Gunawardena
@user1672994 Thanks, that was the first thing I tried, but no luck. Seems to be related to $filter. $search seems to work fine in the graph explorer.Chris Gunawardena

2 Answers

0
votes

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

0
votes

I saw a reference in your code sample to B2C-ExtensionID. Not all of the core Microsoft Graph calls play nicely with B2C tenants.

The most recent MS documentation I've found is from 1/26/21 and can be viewed here

The documentation does not make clear some information I consider rather important for those of us working with B2C. Little comments like this one, found in the Optional query parameters section of this document :

The $count and $search parameters are currently not available in Azure AD B2C tenants.

It is also worth noting that, since B2C doesn't support $count, the presently MS endorsed workaround (which requires using $count, along with a header of "ConsistencyLevel: eventual") for using $orderby cannot be used against a list of B2C users.

So, if you're using Microsoft Graph to work with B2C tenant data you cannot implement useful features like counting your api resposne results, nor can you order them.