Inconsistent Microsoft Graph Api $count response for users
Oct 9
I'm trying to get a total count of users through Microsoft Graph API through my B2C AAD tenant, but the response seems to either error out or is omitting the @odata.count property.
Feedback online is also mixed where some people say that $count is still unsupported even thought the official documentation says that $count is supported for /users.
https://learn.microsoft.com/en-us/graph/query-parameters#count-parameter
I tried through the graph api online version: https://developer.microsoft.com/en-us/graph/graph-explorer?request=users?$count=true&method=GET&version=v1.0
With this result:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
"@odata.count": 31,
"value": [
...
]
}
However doing the same thing through something like postman nets me this result:
GET /v1.0/users?$count=true HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer [token]
ConsistencyLevel: eventual
{
"error": {
"code": "Request_BadRequest",
"message": "This request is not supported by the service",
"innerError": {
"date": "2020-10-09T18:19:44",
"request-id": "4d97fd77-19ad-42f9-9357-66c24c867ce2",
"client-request-id": "4d97fd77-19ad-42f9-9357-66c24c867ce2"
}
}
}
If I remove ConsistencyLevel header, I get a valid response but there is no @odata.count property.
Is there some Graph Api permissions that I am missing, or is this expected?
1 answer
Accepted answer · original discussion
Oct 10
For the B2C tenant the user count is not yet supported for this /users endpoint. But for a general Azure AD tenant it will give you the count when you follow these below steps.
- Select the beta endpoint. (
https://graph.microsoft.com/beta/users?$count=true) - Add $count=true in the QueryString.
- Add
ConsistencyLevel = eventualto the Request headers.
You will see the results as below.
You can also refer this Document.
Please raise a feature request in the Microsoft Graph Feedback Forum so that the product team may add this feature to b2c tenant in future.
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.