Get All Records from an App: The Offset Method

Contents

Overview

This article introduces how to retrieve data of all records from an App using the Get Records API and the Offset Method.

Details of the Offset Method

The Get Records API is defaulted to retrieving up to 100 records. By increasing the limit parameter , this number can be increased to 500 records. To retrieve over 500 records, the Get Records API can be called recursively, using promises.

The Offset Method is one way of calling the Get Records API recursively. The Get Records API is called to retrieve a number of records equal to the value set in the limit parameter. The offset is then shifted, and the function calls itself again. This continues until all records are retrieved from the App.

Sample Code

Navigate to an App, and open the browser’s developer tools. Type the following code into the console and run it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function fetchRecords(appId, opt_offset, opt_limit, opt_records) {
  var offset = opt_offset || 0;
  var limit = opt_limit || 100;
  var allRecords = opt_records || [];
  var params = {app: appId, query: 'limit ' + limit + ' offset ' + offset};
  return kintone.api('/k/v1/records', 'GET', params).then(function(resp) {
    allRecords = allRecords.concat(resp.records);
    if (resp.records.length === limit) {
      return fetchRecords(appId, offset + limit, limit, allRecords);
    }
    return allRecords;
  });
}

fetchRecords(kintone.app.getId()).then(function(records) {
  console.log(records);
});

Data of all records from the currently viewed App should be output into the console. It may take a few seconds before the result is displayed.

Screenshot: Data retrieval output into the console.

Limitations

The maximum value that can be set for the offset parameter is 10,000. If more than 10,000 records need to be obtained, consider other recursive methods or use the Get Cursor REST API.