Skip to main content

Append data to table

Use this API to add data in bulk to an existing table. If you need to add columns, you can also add the configuration information corresponding to the columns in the json saved in the columns file (see Create table API).

Request

# Append (new rows)
curl -vvv -X POST "$API_HOST/open/api/v1/tablenodes/$table_id/rows/append/" \
-H "Authorization: $access-token" \
-d "skipFirstRow=false&autoCreateColumn=true" \
-F "columns=@$file_path" \
-F "rows=@$csv_file_path"

# Merge mode (update existing rows by indexColumnID)
curl -X POST "$API_HOST/open/api/v1/tablenodes/$table_id/rows/append/" \
-H "Authorization: $access-token" \
-F "rows=@data.csv" \
-F "skipFirstRow=true" \
-F "indexColumnID=$index_column_id" \
-F "mergeStrategy=merge"

The request is submitted using a form that contains two fields: columns and rows, which represent the "table column definition" and "data rows" respectively. Refer to the table below for details.

Response body form-data example

KeyValueRequiredNote
skipFirstRowfalseNOSkip the csv header
autoCreateColumnfalseNOCreate new columns (if a column has no id field in the config file)
columnsread_table_columns.jsonYESColumns configuration file. The columns should keep the same order as columns in csv file.
rowsgd_append.csvYESRow data CSV file
indexColumnID$index_column_idNOIndex column ID (24-char hex). Enables merge mode when specified — rows matching existing values in this column are updated; unmatched rows are appended as new.
mergeStrategymergeNOMerge strategy, requires indexColumnID. merge — skip null values, only update specified columns. overwrite — replace entire row. Default behavior without this field is standard append (no merge).

column parameters json format description

KeyTypeDescriptionRequired
arraycolumn listY
∟ idstringcolumn IDY, blank if user want to add a new column
∟ namestringColumn NameYes if new column
∟ typestringcolumn type:multiLineText number datetime singleChoice coordinateYes if new column
∟ typeOptionsobjectcolumn options:When column is number, datetime, or singleChoiceN
∟ formatstringnumber type:number, percentage, commaNumberYES:When number type
∟ precisionstringprecision: 0-5YES:When number type
∟ dateFormatstringdate format: year/month/day month/day/year detailYES:When datetime type
∟ timeFormatstringtime format: hidden 24-hour-clock 12-hour-clockYES:When datetime type
∟ choicesarrayoption list: created automatically when emptyYES:When singleChoice type
∟ namestringoption nameYES:When singleChoice type
∟ colorstringoption color: use a random color when emptyYES:When singleChoice type

Python example

def table_append_data(access_token, table_id, data, columns_file, data_file):
url = '%s/open/api/v1/tablenodes/%d/rows/append/' % (API_HOST, table_id)
files = {'rows': open(data_file, 'rb'),
'columns': open(columns_file, 'rb')}
headers = {'Authorization': access_token}
req = requests.post(url, data=data, headers=headers, files=files)
return req.json()

# create table using csv
data = {
'projectID': project['id'],
'name': 'test-csv-upload',
'skipFirstRow': True
}
resp = ma.create_table(access_token, data,
'data/create_table_columns.json',
'data/gd.csv')

table = resp['detail']
resp = ma.read_table(access_token, table['id'], '', '')
with open('data/read_table_columns.json', 'w') as f:
json.dump(resp['detail']['columns'], f)

data = {
'skipFirstRow': True,
'autoCreateColumn': False
}

resp = ma.table_append_data(access_token, table['id'],
data,
'data/read_table_columns.json',
'data/gd.append.csv')

Response

Response body

Description of some key information

KeyTypeDescription
detailobjectResponse object
∟ idint64Table ID
∟addedColumnsarrayAdded columns (if new columns added)
∟ idstringColumn ID
∟ typestringColumn type
∟typeOptionsobjectColumn options
∟ isPrimarybooleanIs primary column
∟appendRowIDsmapNew row IDs (CSV row index → row ID)
∟rowIDMapmapRow ID mapping (used in merge mode)
∟updatedRowCountintNumber of rows updated (merge mode)
∟columnIDMapmapColumn ID mapping

Response body example

{
"code": 0,
"detail": {
"id": 980,
"name": "newName2",
"type": "table",
"order": 441,
"parentID":null,
"projectID": 264,
"subscribed":false,
"published":false,
"roleInherited":true,
"createTime": "2022-04-15T06:44:21.506295Z",
"updateTime": "2022-04-15T06:48:33.243726Z",
"addedColumns": [
{
"id": "625914457cff69c01aed2d71",
"name": "New-Title1",
"type": "multiLineText",
"typeOptions":null,
"isPrimary":true }
],
"appendRowIDs": {
"0": "625931df04b5540935aef0dd",
"1": "625931df04b5540935aef0de"
},
"importErr":null },
"extra":null,
"message": "OK",
"requestID":null
}