Chilkat Online Tools

Android / Cognite API v1 / Insert rows into a table

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    // 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": [
    //   ]
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateNewArray("items");

    http.SetRequestHeader("content-type","application/json");
    http.SetRequestHeader("api-key","{{api-key}}");

    CkHttpResponse resp = http.PostJson3("https://domain.com/api/v1/projects/{{project}}/raw/dbs/:dbName/tables/:tableName/rows?ensureParent=false","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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}"
    }
  }
}