Cli-kintone Tutorial 2: Add and Delete Records

Introduction

This is the second article of the cli-kintone series, focused on adding and deleting records using cli-kintone.
The previous tutorial can be found here: Cli-kintone Tutorial 1: Export record data.

In this article we will continue to use the Customer Database used in the previous tutorial.

Add Records

STEP 1: Prepare a CSV file

The first step is to prepare a CSV file that will be used to add record data to the kintone App.

You do not have to list every field that's in your App into the CSV file - you may limit the fields you want to add data to, as below:

Make sure to write the field code in the first row, and not the field name.
Save the data as customers.csv.

STEP 2: Add records by specifiying the CSV file

In addition to the authentication option, use the -f option to specify the file to import.

If customers.csv is saved in the same location as the cli-kintone executable file:

If you specify the file path of customers.csv:

 


Check your kintone App on your browser to see if the records were successfully added.

US_01.PNG

Add Records after Deleting Records

STEP 1: Add Records After Deleting all Records

Use the -f and -D option to delete all records before adding new records.

If no query is specified, all records in the App will be deleted before records are added.

STEP 2: Add Records After Deleting filtered records

To delete only specified records before adding new records, you will need to filter the records to be deleted using the -q option. Refer to this page on how to write queries.

In the example below, the 5 latest records that have "Krispy" as the contact name are deleted before the new records are added:

STEP 3: Delete Records Without Adding Records

You can delete records without adding data by making an empty CSV file, specifying it with the -f option and then using the -D option:

To make an empty CSV file "empty.csv" on Windows:

For Mac and Linux, use one of the commands below in the terminal:

Add Records with Table data

In this example, we will use the Expense Report App that was used in the previous tutorial.

STEP 1: Create a CSV file containing table data

To add records that include table data, add an * symbol in the first column of the row that contains the field codes. Also add the * symbol to each row that contains the first table data row of tables in each record.

To avoid making mistakes, use a CSV file exported by cli-kintone as reference.

Save the contents above as tabledata.csv.

STEP 2: Add records by specifying the CSV file

Use the -f option to specify the CSV file to add records with table data.

 

The contents of the CSV file looks like the below when opened in Excel.

US_02.PNG

 

These are the screenshots of the three records that have data added to them. The data in the colored rectangles above match the data in the colored rectangles below.

US_03.PNG

CSV data for Check box and Multi-choice fields

Check box fields and Multi-choice fields are fields that can hold multiple values. A carriage return must be used to separate the multiple values for these fields. If you view the data in Excel, the multiple values can be seen on several lines inside one cell. When editing on excel, use the Alt + Enter shortcut in a cell for a carriage return.

The same goes for the tables. If the table contains these fields, separate the multiple values within these fields with carriage returns.

Example CSV data 

US_04.PNG


The two records in the above images can be represented with the following CSV:

 

In Excel, this looks like the below:

US_05.PNG

Example CSV data for Tables

US_06.PNG

The two records in the above images can be represented with the following CSV:

In Excel, this looks like the below:

US_07.PNG

How to debug if records fail to be added

Although cli-kintone returns error messages from kintone, sometimes it may be easier to identify the problem by checking the requests on the Audit Log in the System Administration page.

Click the gear icon on the upper right menu of kintone, and go to "User & System Administration" -> "Audit Logs" -> "View & Download".

From the Audit Log list, you can see what record operations were performed and their success/failure as well as the details of each operation by clicking the "i" mark on the left side of the table.


By looking at this information, you can see if requests from cli-kintone are successfully reaching your kintone environment and to see what errors are the cause of the issue.

US_08.PNG

 

 

This is the end of Tutorial 2 for cli-kintone.

We hope this has solved any tricky issues involving managing table data and fields that can hold multiple values.

 

 

<<< Go back to Cli-kintone Tutorial 1: Export record data

Was this article helpful?
0 out of 0 found this helpful
Comments
Please sign in to leave a comment.