Paging

Overview

Paging defines the maximum number of rows to include in the response, e.g. when you need to retrieve top 10 declining line items in terms of impressions for a given period. Keep in mind:

  • Paging property is optional.
  • Both page and pageSize properties accept integer values.
  • If pageSize is not provided, the query returns the default of 250 rows (rows are indexed starting from 1, not 0).
  • If page property is not provided, the starting index is 1 (pages are indexed starting from 1, not 0).
  • API can return a maximum of 1000 rows per request, no matter how many you ask for.
  • For situations, when totalRowCount exceeds 1000 and you want to retrieve and iterate through all the rows of the result set, use this JavaScript sample.

JSON Sample


        {
   "filter": { ... },
   "metrics": [ ... ],
   "paging": {
      "page": 1, // page number
      "pageSize": 5 // rows per page
   },
   "sort": { ... }
}
    

JavaScript Paging Integration


        var fetch = function(request, size) {
  
    var page = 1;
    var calculatedSize = calculatePageSize(page, size);
  
    var response = null;
    request.includeRowCount = true;
    while (calculatedSize > 0) {
          
        request.paging = {
            page: page,
            size: calculatedSize
        };
          
        response = post(request);
        if (page > 1)
            response.reportData.rows = response.reportData.rows.concat(response.reportData.rows);
          
        page++;
        calculatedSize = calculatePageSize(page, size, response.totalRowCount);
    }
      
    return response;
};
  
var calculatePageSize = function (page, size, total) {
     
    var result = size;
      
    if (total && size > 0) { 
        var pages = parseInt(total / size);
          
        if (page <= pages)
            result = size;
        else if (page == pages + 1)
            result = total % size;
        else
            result = 0;
    }
          
    return result;
};
    
Help

Still have questions?

If you can't find an answer to your question here, email our Support team