Paginate API response

Paginate API response

When you make REST API calls to some endpoints to query visualization data, for instance /tspublic/v1/pinboarddata, the APIs may return many rows of data in response. You can paginate the JSON response and retain the order of data across all pages. Given the ability to paginate, you can quickly populate tables and make new REST calls every time you go to the next page of the data on the table. There is significant load time if you want to populate the data table with many rows (greater than 1000).

To paginate results in your API response, add the following parameters to the query:

pagesize determines the number of rows to include.

 {
    "name": "pagesize",
    "description": "pagesize: The number of rows.",
    "defaultValue": "-1",
    "type": "integer"
 }

Offset determines the starting point.

 {
    "name": "offset",
    "description": "Offset: The starting point",
    "defaultValue": "-1",
    "type": "integer"
 }

pageNumber is an alternate way to determine the offset. You must make a call with pageNumber = 1 first, and then you can access any page. Calling with pageNumber != 1 as the initial call will fail. pageNumber = 0 is not a valid value.

{
    "name": "pagenumber",
    "description": "PageNumber: This is an alternate way to set offset. This is 1-based indexing. Offset = (pageNumber - 1) * pageSize.",
    "defaultValue": "-1",
    "type": "integer"
}

FormatType is the JSON format type.

{
    "name": "formattype",
    "description": "FormatType: This sets the JSON format type. Values that are allowed are FULL and COMPACT.",
    "defaultValue": "COMPACT",
    "type": "string"
}

COMPACT is the default type, and is formatted as follows: ['col1', 'col2'] [1, 'a']. While FULL is formatted like this:

{'col1': 1 'col2': 'a'}

Example🔗

The following example shows ThoughtSpot data that is being populated in a table:

{
    "totalRowCount": 1500,
    "pageSize": 1000,
    "pageNumber": 1,
    "data":
    [
       {
            "key1": "value1",
            "key2": "value2"
        },
        {
            "key1": "value1",
            "key2": "value2"
        }
    ]
}