user989988
user989988

Reputation: 3746

Get count of users while reading from AAD [Microsoft Graph]

I was following this documentation https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=csharp to run some graph query on AAD objects as follows:

await _graphServiceClient
         .Users.Request()
         .Request(new Option[] { new QueryOption("$count", "true") })
         .Header("ConsistencyLevel", "eventual")
         .Filter("endsWith(mail,'tenant.com')")
         .GetAsync();

I see the following error:

enter image description here

What am I missing and how do I resolve the same?

Upvotes: 0

Views: 898

Answers (2)

Rukmini
Rukmini

Reputation: 16004

I tried to reproduce the same in my environment and got the below results:

To retrieve the list of users with Mail-ID, I executed the below query in Microsoft Graph Explorer:

GET https://graph.microsoft.com/v1.0/users?$count=true&$filter=endsWith(mail,'@tenant.com')

ConsistencyLevel:eventual

Response:

enter image description here

You can make use of the below sample CSharp code:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var users = await graphClient.Users
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("endsWith(mail,'@tenant.com')")
.GetAsync();

Upvotes: 1

Tiny Wang
Tiny Wang

Reputation: 16066

await _graphServiceClient
         .Users.Request(new Option[] { new QueryOption("$count", "true") })
         .Header("ConsistencyLevel", "eventual")
         .Filter("endsWith(mail,'tenant.com')")
         .GetAsync();

Upvotes: 1

Related Questions