Quickstart Nodejs
Requirement
How to use
Step 1: Run commands
$ mkdir test
$ cd ./test
$ npm init
$ npm install --save @kintone/kintone-js-sdk
Step 2: Add index.js file to test/ folder
Get record sample
Promise
const kintone = require('@kintone/kintone-js-sdk');
let auth = new kintone.Auth();
const passwordAuthParam = {
username: 'YOUR_USER_NAME',
password: 'YOUR_PASSWORD'
};
auth.setPasswordAuth(passwordAuthParam);
const connParam = {
domain: 'YOUR_DOMAIN',
auth: auth
};
let connection = new kintone.Connection(connParam);
let kintoneRecord = new kintone.Record({connection});
const params = {
app: 'YOUR_APPID',
id: 'RECORD_ID'
};
kintoneRecord.getRecord(params).then((rsp) => {
console.log(rsp);
}).catch((err) => {
// The promise function always reject with KintoneAPIExeption
console.log(err.get());
});
async/await
const kintone = require('@kintone/kintone-js-sdk');
let auth = new kintone.Auth();
const passwordAuthParam = {
username: 'YOUR_USER_NAME',
password: 'YOUR_PASSWORD'
};
auth.setPasswordAuth(passwordAuthParam);
const connParam = {
domain: 'YOUR_DOMAIN',
auth: auth
};
const connection = new kintone.Connection(connParam);
const kintoneRecord = new kintone.Record({connection});
const params = {
app: 'YOUR_APPID',
id: 'RECORD_ID'
};
const getRecord = async () => {
try {
let recordResult = await kintoneRecord.getRecord(params);
console.log(recordResult);
} catch (error) {
// The promise function always reject with KintoneAPIExeption
console.log(error.get());
}
}
getRecord();
Step 3: Run index.js file
$ node index.js
Get record response
Response success
{
"record":{
// record data should be here
}
}
Response error
{
id: '{ID}',
code: '{CODE}',
message: '{Message string}',
errors: '{JSON String}'
}