Most API calls that result in a list response can be paged by using the hasMore
property when it is true
. Paging results can be accomplished using limit
and where
query arguments or a combination of where
, limit
and skip
query arguments.
The recommended method for paging is using indexed, unique identifiers such as _id
, sorting by the identifier and applying a where argument. For example:
?where={"_id": {"$gt": "561b5a700000000000000000"}}&sort={"_id": 1}
If forced to sort by non-unique fields, like name.last
, it is possible to fall back on using the skip
argument for paging, though it is not as efficient as using a unique indexed field. Additionally, paging using skip
is only effective for small result sets (e.g. less than a few hundred records).
In the below example, we have a custom "Conversation" object. Suppose there are 20 conversations available to a user. An initial call to GET /conversations?paths[]=_id&limit=2&sort={"_id": 1}
results in the following response:
GET /c_conversations?paths[]=_id&limit=2&sort={"_id": 1}
{
"data": [
{
"_id": "551c76c3bad12f302b343481",
"object": "c_conversation"
},
{
"_id": "551c76c4bad12f302b343489",
"object": "c_conversation"
}
],
"hasMore": true,
"object": "list"
}
The response's hasMore
property is true, so the caller knows there are more results. The last _id
in the list is used in the next where
argument like this:
GET /conversations?paths[]=_id&limit=2&where={"_id": {"$gt": "551c76c4bad12f302b343489"}}&sort={"_id": 1}
{
"data": [
{
"_id": "551c76c3bad12f302b343492",
"object": "c_conversation"
},
{
"_id": "551c76c4bad12f302b343511",
"object": "c_conversation"
}
],
"hasMore": true,
"object": "list"
}
List Property Paging
Lists of contexts can be paged by prefixing query arguments with the property name. For example:
GET /c_patientfiles/550891732390ac1832f3317f/?paths[]=connections.access&connections.where{"_id":{"$gt":"550b9a25c59c1ef032ab641c"}}
{
"_id": "550891732390ac1832f3317f",
"object": "c_patientfile",
"connections": {
"object": "list",
"hasMore": "false",
"data: [{
"_id": "551ce5dfcd3227a41dfa7e9d",
"object": "connection",
"access": 2
}]
}
}