Kintone REST API Request

The Kintone REST API Request enables running Kintone REST APIs from JavaScript code.
Relying solely on the JavaScript API has limitations. For example, retrieving data from all records within an App requires the use of the Kintone REST API.
To perform this action, use the Kintone REST API request to run the REST API.
It is not necessary to specify request headers when using this API.

Kintone REST API Request - kintone.api()

REST APIs with the GET, POST, PUT, DELETE method can be used.

Function

kintone.api(pathOrUrl, method, params, successCallback, failureCallback)

Request Parameters

PARAMETER VALUE REQUIRED DESCRIPTION
pathOrUrl String Yes The path of the Kintone REST API, or the URL obtained with kintone.api.url.
If the URL of the API is https://{subdomain}.kintone.com/k/v1/xxx.json, then specify the parameter as /k/v1/xxx.json. If the app is to be used inside a guest space, specify the parameter as kintone.api.url("/k/v1/xxx.json", true).
method String Yes The HTTP method. Specify one of the following: GET / POST / PUT / DELETE.
params Object Yes The parameters to be used with the API, specified as an object.
successCallback Function Optional The callback function called when the API succeeds.
The parameter for this function is an object.
If ignored, a kintone.Promise object will be returned that can be fulfilled with the parameter passed to the callback.
failureCallback Function Optional The callback function called when the API fails.
The parameter for this function is a JSON response. If the JSON response cannot be parsed, an unparsed string will be given.
If the callback is ignored, a kintone.Promise object will be returned that can be rejected with the parameter passed to the failureCallback.

Returns

A kintone.Promise object will be returned if the successCallback or failureCallback parameters are ignored. Otherwise, there will be no response.

Sample Request

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function getRecords() {
  var body = {
    app: 1
  };

  // Kintone REST API Request calling the Kintone Get Record API
  kintone.api(kintone.api.url('/k/v1/records.json', true), 'GET', body, function(success) {
    // The function called on success
    var records = success.records;
    var recordSize = records.length + 1;
    window.alert('There are now currently ' + recordSize + ' records in this App.');
  }, function(error) {
    // The function called on error
    var errormsg = 'There was an error when retrieving the data.';
    window.alert(errormsg);
  });
}

kintone.events.on('app.record.create.submit', getRecords);

Sample Request Using Promises

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
kintone.events.on('app.record.create.submit', function getRecords(event) {
  var body = {
    app: 1
  };

  kintone.api(kintone.api.url('/k/v1/records.json', true), 'GET', body).then(function(success) {
    var records = success.records;
    var recordSize = records.length + 1;
    window.alert('There are now currently ' + recordSize + ' records in this App.');
  }, function(error) {
    var errormsg = 'There was an error when retrieving the data.';
    window.alert(errormsg);
  });
});

Limitations

The following Kintone REST APIs cannot be run.

To execute from a customization applied to the App, use the browser's Fetch API or XMLHttpRequest.

Notes

When a GET request is sent using kintone.api(), and the length exceeds 4KB, the X-HTTP-Method-Override header will automatically be added and the request will be sent as a POST request.
For more information, refer to the following article:
X-HTTP-Method-Override