SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

sitePages API (beta): $count parameter only reports what's returned, not overall number #9159

Open heinrich-ulbricht opened 1 year ago

heinrich-ulbricht commented 1 year ago

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

other (enter in the "Additional environment details" area below)

Developer environment

Windows

What browser(s) / client(s) have you tested

Additional environment details

Describe the bug / error

My goal is to get the count of pages in the Site Pages library of a site.

According to the beta endpoint documentation the $count parameter is supported.

I add the $count parameter, the result contains a count, but the count only reflects the number of returned pages - which makes no sense. I expect the overall count of pages.

Steps to reproduce

Call https://graph.microsoft.com/beta/sites/<siteid>/pages/microsoft.graph.sitePage?$count=true on a site with more than 200 pages (200 pages seems to be the default response-page size, so make the number of pages in the site larger).

Expected behavior

I expect the overall number of pages to be returned. I have a test site with 130000 pages, so I'd expect a count of 130000 to be returned. Not 200.

The response for above call for me yields (in Graph Explorer):

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#sites('<siteid>')/pages/microsoft.graph.sitePage",
    "@odata.count": 200,
    "@odata.nextLink": "https://graph.microsoft.com/beta/sites/<siteid>/pages/microsoft.graph.sitePage?$count=true&$skiptoken=<snip>",
    "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET sites('<siteid>')/pages/microsoft.graph.sitePage?$select=promotionKind,reactions",
    "value": [

// <snip 200 pages>
   ]
}

By the way when restricting the call with the $top=1 parameter to return only one item, the count is .... 1. This count is useless XD

How is the $count param intended to work for sitePages?

ghost commented 1 year ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

nick-pape commented 1 year ago

Are you only attempting to get the count? The pagination makes sense by default, as getting 130,000+ pages returned in a single API call is probably unnecessarily taxing to both the client and the server.

If you are trying to get only the count, could you try using $count as a URL segment instead of a query parameter (i.e. as a / instead of a ?, e.g.:

https://graph.microsoft.com/beta/sites/<siteid>/pages/microsoft.graph.sitePage/$count=true

heinrich-ulbricht commented 1 year ago

Yes I'm only interested in the count. I'm not expecting 130000 pages to be returned. I just mentioned the number since it might make a difference in the backend when getting the count.

Interesting approach using it as URL segment, didn't notice this option. But it does not want it:

image

https://graph.microsoft.com/beta/sites/<siteid>/pages/microsoft.graph.sitePage/$count=true

returns:

{
    "error": {
        "code": "BadRequest",
        "message": "The request URI is not valid. Since the segment 'microsoft.graph.sitePage' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource.",
        "innerError": {
            "date": "2023-08-22T19:38:05",
            "request-id": "0bf73008-6f71-4fec-b24e-cc17736f795d",
            "client-request-id": "5a8b5de1-ed7c-a9cc-00f2-f460f45a8c8b"
        }
    }
}