Skip to content

Bulk Request

The Bulk Request API allows multiple API requests to run on multiple kintone apps. The below API can be used with the Bulk Request API:

  • Add Record
  • Add Records
  • Update Record
  • Update Records
  • Delete Records
  • Update Status
  • Update Statuses
  • Update Assignees

Constructor

Parameters

Name Type Required Description
params Object (conditional) Required for nodejs
Constructor params.
params.connection Connection (conditional) The connection module of this SDK. If initializing in browser environment on kintone, this parameter can be ommited to use session authentication.

Sample code

Init bulk request module Javascript
  (function(kintoneJSSDK) {
    'use strict';
    // with connection
    // Define Authentication object
    var kintoneAuth = new kintoneJSSDK.Auth();
    var paramsAuth = {
        username: 'YOUR_USER_NAME',
        password: 'YOUR_PASSWORD'
    };
    kintoneAuth.setPasswordAuth(paramsAuth);

    var paramsConnection = {
        domain: 'YOUR_DOMAIN',
        auth: kintoneAuth
    };
    var connection = new kintoneJSSDK.Connection(paramsConnection);
    // with connection
    var kintoneBulkRequest = new kintoneJSSDK.BulkRequest({connection});

    // without connection, module will use session authentication of kintone
    var kintoneBulkRequest = new kintoneJSSDK.BulkRequest();
  }(window.kintoneJSSDK));


Nodejs

  const kintone = require('@kintone/kintone-js-sdk');

  const kintoneAuth = new kintone.Auth();
  const paramsAuth = {
      username: 'YOUR_USER_NAME',
      password: 'YOUR_PASSWORD'
  };
  kintoneAuth.setPasswordAuth(paramsAuth);

  const paramsConnection = {
      domain: 'YOUR_DOMAIN',
      auth: kintoneAuth
  };
  const connection = new kintone.Connection(paramsConnection);
  const kintoneBulkRequest = new kintone.BulkRequest({connection});

Methods

All below methods (excluded execute() method) will add request to queue, you must execute the execute() function to get result of BulkRequest.

addRecord({app, record})

Parameters

See at Record - addRecord

Return

BulkRequest

addRecords({app, records})

Parameters

See at Record - addRecords

Return

BulkRequest

updateRecordByID({app, id, record, revision})

Parameters

See at Record - updateRecordByID

Return

BulkRequest

updateRecordByUpdateKey({app, updateKey, record, revision})

Parameters

See at Record - updateRecordByUpdateKey

Return

BulkRequest

updateRecords({app, records})

Parameters

See at Record - updateRecords

Return

BulkRequest

deleteRecords({app, ids})

Parameters

See at Record - deleteRecords

Return

BulkRequest

deleteRecordsWithRevision({app, idsWithRevision})

Parameters

See at Record - deleteRecordsWithRevision

Return

BulkRequest

updateRecordAssignees({app, record, assignees, revision})

Parameters

See at Record - updateRecordAssignees

Return

BulkRequest

updateRecordStatus({app, id, action, assignee, revision})

Parameters

See at Record - updateRecordStatus

Return

BulkRequest

updateRecordsStatus({app, records})

Parameters

See at Record - updateRecordsStatus

Return

BulkRequest

execute()

Execute the bulk request and get data response

Parameters

(none)

Return

[Promise]

Sample code

Execute bulk request Javascript

  var responseBulkRequest = kintoneBulkRequest
    .addRecord({/* [Args]*/})
    .addRecords({/* [Args]*/})
    .updateRecordByID({/* [Args]*/})
    .updateRecordByUpdateKey({/* [Args]*/})
    .updateRecords({/* [Args]*/})
    .deleteRecords({/*[Args]*/})
    .deleteRecordsWithRevision({/* [Args]*/})
    .updateRecordAssignees({/* [Args]*/})
    .updateRecordStatus({/* [Args]*/})
    .updateRecordsStatus({/* [Args]*/})
    .execute();

  responseBulkRequest.then((resp) => {
    console.log(resp);
  }).catch((err) => {
    // The error will be an array if there are errors occur in addRecord, addRecords, updateRecords, updateRecords,deleteRecords... function 
    if (Array.isArray(err)) {  
        for (let i = 0; i < err.length; i++) {
            // Need to check the type of error because err array can have some empty object like: 
            // [KintoneAPIException ,{},{},{},{}]
            if (err[i] instanceof kintoneJSSDK.KintoneAPIException) {
                console.log(err[i]);
            }   
        }
    } 
    // The error will be a KintoneAPIException if setting wrong Auth, Connection ... for BulkRequest
    else {  
        console.log(err);
    }
  });

Nodejs

  const responseBulkRequest = kintoneBulkRequest
    .addRecord({/* [Args]*/})
    .addRecords({/* [Args]*/})
    .updateRecordByID({/* [Args]*/})
    .updateRecordByUpdateKey({/* [Args]*/})
    .updateRecords({/* [Args]*/})
    .deleteRecords({/*[Args]*/})
    .deleteRecordsWithRevision({/* [Args]*/})
    .updateRecordAssignees({/* [Args]*/})
    .updateRecordStatus({/* [Args]*/})
    .updateRecordsStatus({/* [Args]*/})
    .execute();

  responseBulkRequest.then((resp) => {
    console.log(resp);
  }).catch((err) => {
    if (Array.isArray(err)) {  // The error will be an array if there are errors occur in addRecord, addRecords, updateRecords, updateRecords,deleteRecords... function 
        for (let i = 0; i < err.length; i++) {
            // Need to check the type of error because err array can have some empty object like: 
            // [KintoneAPIException ,{},{},{},{}]
            if (err[i] instanceof kintone.KintoneAPIException) {
                console.log(err[i]);
            }
        }
    } else {  // the error will be an element if setting wrong Auth, Connection ... for BulkRequest
        console.log(err);
    }
  });

Reference