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.

Contents

Kintone REST API Request - kintone.api()

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

Function

kintone.api(pathOrUrl, method, params, opt_callback, opt_errback)

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.
opt_callback 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.
opt_errback 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 errback.

Response

A kintone.Promise object will be returned if the callback parameter is 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.

Get URL - kintone.api.url()

Returns a URL from a shortened API path.

Function

kintone.api.url(path, opt_detectGuestSpace)

Request Parameters

PARAMETER VALUE REQUIRED DESCRIPTION
path String Yes The Kintone REST API path string beginning with /.
If the URL of the API is https://{subdomain}.kintone.com/k/v1/xxx.json, then specify the parameter as /k/v1/xxx.
opt_detectGuestSpace Boolean Optional If this is set to true, and is used in a guest space app, the URI of the guest space will be returned. Default is false.

Response

A URL string.

Sample Response

1
https://{subdomain}.kintone.com/k/v1/records.json

Sample Request

1
2
var url = kintone.api.url('/k/v1/records.json');
console.log(url);

Get URL (including query) - kintone.api.urlForGet()

Returns a URL including a query string, from an API path and parameters.

Function

kintone.api.urlForGet(path, params,opt_detectGuestSpace)

Request Parameters

PARAMETER VALUE REQUIRED DESCRIPTION
path String Yes The Kintone REST API path string beginning with /.
If the URL of the API is https://{subdomain}.kintone.com/k/v1/xxx.json, then specify the parameter as /k/v1/xxx.
params Object Yes The parameters to be used with the API, specified as an object.
opt_detectGuestSpace Boolean Optional If this is set to true, and is used in a guest space app, the URI of the guest space will be returned. Default is false.

Response

A URL string including a query string, with URL encoded parameters.

Sample Response

1
https://{subdomain}.kintone.com/k/v1/records.json?app=7&fields[0]=text_0

Sample Request

1
2
var urlForGet = kintone.api.urlForGet('/k/v1/records.json', {app: 7, fields: ['text_0']});
console.log(decodeURIComponent(urlForGet));

Get CSRF Token - kintone.getRequestToken()

Retrieves a CSRF token to be used for file downloads/uploads.
This can be used for all APIs that have an HTTP method of POST, PUT and DELETE. APIs with an HTTP method of GET do not need a CSRF token.

Function

kintone.getRequestToken()

Request Parameters

None

Response

A string.

Available Period

86400 seconds (1 day) from the last access.

Sample Response

1
19324485-251e-2f6h-9332-824c9933g53e

Sample Request

1
2
var token = kintone.getRequestToken();
console.log(token);

Sample for APIs using Query Strings

1
https://{subdomain}.kintone.com/k/v1/records.json?__REQUEST_TOKEN__=19324485-251e-2f6h-9332-824c9933g53e

Sample for APIs using JSON

1
2
3
{
  "__REQUEST_TOKEN__": "19324485-251e-2f6h-9332-824c9933g53e"
}

Request headers needed with the APIs

Header Content
X-Requested-With XMLHttpRequest
Content-Type application/json