Kintone REST API Request

The Kintone REST API Request allows you to run Kintone REST APIs from your JavaScript code.
You'll find that you are limited to several actions when just completely relying on the JavaScript API - for example, you'll need to use the Kintone REST API if you need to retrieve data of all the records inside your app.
This is where you will 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.

Response

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

File upload/downloads cannot be run. You will need to retrieve the CSRF token, and run an HTTP request.