$count=true not working as expected on /sites

Alexandre Caron 20 Reputation points
2024-11-01T15:21:57.4166667+00:00

What

When calling https://graph.microsoft.com/v1.0/sites?$count=true with the header ConsistencyLevel: eventual, the @odata.count always equals $top or the amount of sites returned instead of the total amount of sites.

This behavior does not match the documentation or other endpoint like v1.0/groups for example.

Examples

When calling https://graph.microsoft.com/v1.0/sites?$top=1&$count=true I get:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
  "@odata.count": 1,
  "value": [...]
}

When calling https://graph.microsoft.com/v1.0/sites?$count=true I get:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
  "@odata.count": 200, <- I have more than 200 sites on my tenant
  "value": [...]
}
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-11-04T06:37:22.88+00:00

    Hello Alexandre Caron,

    Thank you for reaching out to Microsoft Support!

    After testing, it turns out, as you stated, that when the $count argument is used on the sites endpoints, the value of @odata.count is always equal to $top or the number of sites returned, not the total number of sites, which does not match the other endpoints. As Vasil Michev said, for the $count parameter, each endpoint has its own implementation, which is not consistent, and some endpoints do not even support the query parameter.

    Therefore, you are better off counting the site on the client side. At the same time you can here the function of the parameters of the endpoint $count feedback.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2024-11-01T17:46:27.31+00:00

    That's the thing about Graph, each workload has its own implementation, zero consistency. Some endpoints do not even support $count. In this instance, you're better off counting the sites client-side.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.