Export Data with the Command Line Tool
Overview
This article introduces how to export data from Kintone using cli-kintone .
This tutorial uses Kintone Apps that are available in the Kintone Marketplace .
Initial Setup
This section introduces the needed Kintone Apps and required settings. The Customer Database App and the Expense Report App will be created.
Create a Customer Database App
-
First, create a new Kintone App. From the Kintone Marketplace, click Marketing, and choose Customer Database.
-
Add at least two records of data.
Create an Expense Report App
-
Create another Kintone App. From Kintone Marketplace, scroll down and choose Expense Report.
-
Add at least two sample records with more than one expense details.
Generate an API Token
Follow the steps in the Generating API Tokens article to generate an API token for both apps. Make sure to check the View Records option, and take note of the API token, as it is needed in the later steps.
STEP 1. Export Record Data to the Console
Use the
Customer Database App
for step 1 to step 4.
To display records, use the record export
command.
In addition, specify the Kintone domain, App ID and API Token via the --base-url
, --app
and --api-token
options.
|
|
--base-url
: The subdomain to retrieve records from--app
: The App ID to retrieve records from--api-token
: API token copied from Initial Setup
When the command is run, the record information will be output in a CSV format. The headers of the CSV will be the field codes specified within the App.
Example
|
|
STEP 2. Export to a CSV File
To export to a CSV file, use the redirect function (>
) to pipe the output into a file. For example, the following command exports the data to "records.csv".
Example
|
|
When the output directory is not specified, the file will be exported to the directory where the cli-kintone.exe file is located.
Specify the character encoding
By default, string data is exported in UTF-8.
To export to a file with other character encoding, use the --encoding
option. For example, the following command exports the data with Shift-JIS encoding.
Example
|
|
STEP 3. Specify the Fields to Export
To specify the fields to export, use the --fields
option and specify the field codes. For example, the following command exports data only from the Company Name, Representative, and Email fields.
|
|
STEP 4. Export Data with Queries and Sorting
The --condition
option and the --order-by
option can be used to specify queries and the sort order.
cli-kintone queries require using escape characters. For example, when specifying the value Marketing
for the department
field, set the query as: --condition department=\"Marketing\"
. The escape character \
is used to escape the "
.
For more information on queries, refer to the following article:
How to Write cli-kintone Queries
|
|
--condition
option: a query for filtering data.--order-by
option: a query for ordering data.
Example
|
|
STEP 5. Export Table Data
Use the Expense Report App for this section.
As stated in the
Additional Notes on Exported Files
article of the Kintone Help, table data from each record will be exported into multiple rows.
In the file, each record is composed of a line with the *
symbol in the first column and its subsequent lines without the *
symbol.
Example
|
|
Use the below command in the command line to export the table data to a CSV file:
|
|
Below is how the exported result in the CSV file would look like in Excel:
The first row of the exported CSV file has an *
symbol in the first column followed by a field code. The *
symbol informs the user that table data exists in this exported CSV file.
Row 2 and 5 include an *
symbol in the first column. This indicates that these rows, and rows below it that don't contain an *
symbol, are data of 1 record of the App.
The absence of the *
symbol in some rows after the first indicates that they represent data from the second or later row inside the table of the record.