Chilkat Online Tools

TCL / Cognite API v1 / Insert rows into a table

Back to Collection Items

load ./chilkat.dll

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set http [new_CkHttp]

# Use this online tool to generate code from sample JSON: Generate Code to Create JSON

# The following JSON is sent in the request body.

# {
#   "items": [
#   ]
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateNewArray $json "items"

CkHttp_SetRequestHeader $http "content-type" "application/json"
CkHttp_SetRequestHeader $http "api-key" "{{api-key}}"

# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://domain.com/api/v1/projects/{{project}}/raw/dbs/:dbName/tables/:tableName/rows?ensureParent=false" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkJsonObject $json

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "items": []
}'
https://domain.com/api/v1/projects/{{project}}/raw/dbs/:dbName/tables/:tableName/rows?ensureParent=false

Postman Collection Item JSON

{
  "id": "postRows",
  "name": "Insert rows into a table",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "raw",
        "dbs",
        ":dbName",
        "tables",
        ":tableName",
        "rows"
      ],
      "query": [
        {
          "key": "ensureParent",
          "description": "Create database/table if it doesn't exist already",
          "value": "false",
          "disabled": true
        }
      ],
      "variable": [
        {
          "key": "dbName",
          "description": "Name of the database.",
          "disabled": true,
          "type": "string"
        },
        {
          "key": "tableName",
          "description": "Name of the table.",
          "disabled": true,
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "api-key",
        "value": "{{api-key}}",
        "description": "An admin can create API keys in the Cognite console."
      },
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "description": "Insert rows into a table. It is possible to post a maximum of 10000 rows per request.\nIt will replace the columns of an existing row if the rowKey already exists.\n\nThe rowKey is limited to 1024 characters which also includes Unicode characters.\nThe maximum size of columns are 5 MiB, however the maximum size of one column name and value is 2621440 characters each.\nIf you want to store huge amount of data per row or column we recommend using the Files API to upload blobs, then reference it from the Raw row.\n\nThe columns object is a key value object, where the key corresponds to the column name while the value is the column value.\nIt supports all the valid types of values in JSON, so number, string, array, and even nested JSON structure (see payload example to the right).\n\n**Note** There is no rollback if an error occurs, which means partial data may be written. However, it's safe to retry the request, since this endpoint supports both update and insert (upsert).\n",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": []\n}"
    }
  }
}