Update row data to a table
Use this API to update row data in bulk to an existing table
Request
curl -vvv -X PATCH "$API_HOST/open/api/v1/tablenodes/$table_id/rows/" -H "Authorization: $access-token" -d "autoCreateColumn=true" -F "config=@$file_path" -F "rows=@$csv_file_path"
Request form-data example
Key | Value | Required | Note |
---|---|---|---|
autoCreateColumn | false | NO | Create new columns( if a column has no id field in the config file) |
config | create_table_update.json create_table_updateByColumnID.json | YES | Config file |
rows | create_table.data | Yes | Row data |
Python example
def update_rows(access_token, table_id, row_ids, columns_config, data):
config_data = {
'rowIDs': row_ids,
'columns': columns_config
}
files = {
'config': io.StringIO(json.dumps(config_data)),
'rows': io.StringIO('\n'.join(data))
}
headers = {'Authorization': access_token}
url = '%s/open/api/v1/tablenodes/%d/rows/' % (API_HOST, table_id)
resp = requests.patch(url, files=files, headers=headers)
return resp.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'], '', '')
columns = resp['detail']['columns']
# update the last 20 rows
col_id = [i['id'] for i in resp['detail']['columns'] if i['name'] == 'ID'][0]
name_id = [i['id'] for i in resp['detail']['columns'] if i['name'] == 'Name'][0]
updated_rows = []
updated_row_ids = {}
row_cnt = 0
for row in resp['detail']['rows'][:-20]:
row_cnt += 1
updated_row_ids['%d' % row_cnt] = row['id']
item = ','.join((row['cells'][col_id],
'%s-updated' % row['cells'][name_id]))
updated_rows.append(item)
resp = ma.update_rows(access_token, table['id'],
updated_row_ids, columns, updated_rows)
Response
Response body
Description of some key information
Key | Type | Description |
---|---|---|
detail | object | Response boject |
∟ id | int64 | Table ID |
∟addedColumns | array | Added columns (if new columns added) |
∟ id | string | Column ID |
∟ type | string | Column type |
∟typeOptions | object | Column options |
∟ isPrimary | boolean | Is primary column |
∟appendRowIDs | map | New row IDs |
Response body example
{
"code": 0,
"detail": {
"tableNodeID": 486,
"addedColumns": [
{
"id": "625f7d5433e915d1f24e3b8e",
"tableNodeID": 486,
"name": "新字段-开发商",
"type": "multiLineText",
"typeOptions":null,
"addedViewColumns": [
{
"id": "625f7d5433e915d1f24e3b8e",
"viewID": "625f73c03fdf5d93b0ec1378",
"order": 17,
"width": 200,
"required":false,
"title":null,
"desc":null }
]
}
],
"addedRows":null,
"updatedRows": [
{
"id": "625f73c13fdf5d93b0ec138d",
"cells": {
"625f73c13fdf5d93b0ec1379": "Name1",
"625f73c13fdf5d93b0ec137a": "Address1",
"625f73c13fdf5d93b0ec137b": 49702,
"625f73c13fdf5d93b0ec137c": "2021-12",
"625f73c13fdf5d93b0ec137d": "625f73c13fdf5d93b0ec1389",
"625f73c13fdf5d93b0ec137e": 2003,
"625f73c13fdf5d93b0ec137f": 16,
"625f73c13fdf5d93b0ec1380": 2523,
"625f73c13fdf5d93b0ec1381": 2.48,
"625f73c13fdf5d93b0ec1382": "Service1",
"625f73c13fdf5d93b0ec1383": "Company1",
"625f73c13fdf5d93b0ec1384": "625f73c13fdf5d93b0ec138a",
"625f73c13fdf5d93b0ec1385": "625f73c13fdf5d93b0ec138b",
"625f73c13fdf5d93b0ec1386": "625f73c13fdf5d93b0ec138c",
"625f73c13fdf5d93b0ec1387": "POINT(116.566325 39.914057)",
"625f73c13fdf5d93b0ec1388": "38c7c85c287b6637258768bad7796863"
}
},
{
"id": "625f73c13fdf5d93b0ec13f3",
"cells": {
"625f73c13fdf5d93b0ec1379": "Name2",
"625f73c13fdf5d93b0ec137a": "Address2",
"625f73c13fdf5d93b0ec137b": 32194,
"625f73c13fdf5d93b0ec137c": "2021-12",
"625f73c13fdf5d93b0ec137d": "625f73c13fdf5d93b0ec1392",
"625f73c13fdf5d93b0ec137e": 1990,
"625f73c13fdf5d93b0ec137f": 6,
"625f73c13fdf5d93b0ec1380": 802,
"625f73c13fdf5d93b0ec1381": 1.8,
"625f73c13fdf5d93b0ec1382": "Service2",
"625f73c13fdf5d93b0ec1383": "Company2",
"625f73c13fdf5d93b0ec1384": "625f73c13fdf5d93b0ec13b7",
"625f73c13fdf5d93b0ec1385": "625f73c13fdf5d93b0ec13b8",
"625f73c13fdf5d93b0ec1386": "625f73c13fdf5d93b0ec138c",
"625f73c13fdf5d93b0ec1387": "POINT(116.634641 40.326752)",
"625f73c13fdf5d93b0ec1388": "d9b10362b291a7b90e6de4fcf7d72660"
}
}
],
"updatedColumns":null,
"updateErr":null },
"extra":null,
"message": "OK",
"requestID":null
}