Search code examples
versionone

How to get total count of paged data using query.v1


How do I get the total count of results when paging with the query.v1 endpoint?

rest-1.v1/Data

A request like this:

/rest-1.v1/Data/Member?page=2,0

returns the following:

<Assets total="4" pageSize="2" pageStart="0">...

Note the attribute total="4".

query.v1

Whereas a query like this:

{
  "from": "Story",
  "page":
  {
    "start":0,
    "size":2
  }
}

returns the following:

[
    [
        {
            "_oid": "Story:1007"
        },
        {
            "_oid": "Story:1015"
        }
    ]
]

Note the lack of any total count.

Is there possibly some special parameter I can provide in the select statement to include the count? (Similar to @Count with the rest-1.v1/Data endpoint?)


Solution

  • After further investigation, here is a solution to count results using two queries:

    [
        {
            "from": "Scope",
            "select":["Workitems:Story[AssetState!='Dead'].@Count"],
            "filter":["ID='Scope:0'"]
        },
        {
            "from": "Story",
            "select": ["Name"],
            "filter":["Scope='Scope:0'","AssetState!='Dead'"],
            "page":
                {
                    "start":0,
                    "size":200
                }
        }
    ]
    

    Some clarification on line 4:

    "select":["Workitems:Story[AssetState!='Dead'].@Count"]
    

    After "Workitems" we are down-casting the collection to "Story", and then filtering where the "AssetState" isn't "Dead" to get active stories and finally counting Workitems.

    Here you will find some references and extra documentation:

    VersionOne Grammars