Insert rows into a table
Inserts or replaces up to 10,000 rows. A failed request can leave a partial write. Requires rawAcl:WRITE. See Insert rows.
POST
/
raw
/
dbs
/
{dbName}
/
tables
/
{tableName}
/
rows
JavaScript SDK
await client.raw.insertRows('My company', 'Customers', [{ key: 'customer1', columns: { 'First name': 'Steve', 'Last name': 'Jobs' } }]);from cognite.client.data_classes import RowWrite
rows = [RowWrite(key="r1", columns={"col1": "val1", "col2": "val1"}),
RowWrite(key="r2", columns={"col1": "val2", "col2": "val2"})]
client.raw.rows.insert("db1", "table1", rows)
rows = {
"key-1": {"col1": 1, "col2": 2},
"key-2": {"col1": 3, "col2": 4, "col3": "high five"},
}
client.raw.rows.insert("db1", "table1", rows)
import pandas as pd
df = pd.DataFrame(
{"col-a": [1, 3, None], "col-b": [2, -1, 9]},
index=["r1", "r2", "r3"])
res = client.raw.rows.insert_dataframe(
"db1", "table1", df, dropna=True)
List<RawRow> createRowsList = List.of(RawRow.newBuilder()
.setDbName("dbName")
.setTableName("tableName")
.setKey("key")
.setColumns(Struct.newBuilder()
.putFields("string", Values.of("VAL"))
.putFields("numeric", Values.of("VAL"))
.putFields("bool", Values.of(ThreadLocalRandom.current().nextBoolean()))
.putFields("null_value", Values.ofNull())
.putFields("array", Values.of(ListValue.newBuilder()
.addValues(Values.of(ThreadLocalRandom.current().nextDouble(10000d)))
.build()))
.putFields("struct", Values.of(Structs.of("nestedString", Values.of("myTrickyStringValue")
)))
).build());
List<RawRow> createRowsResults = client.raw().rows().upsert(createRowsList, false);
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"key": "some rowKey",
"columns": {
"some int-col": 10,
"some string-col": "string example",
"some json-col": {
"test": {
"foo": "nested"
}
},
"some array-col": [
0,
1,
3,
4
]
}
}
]
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'key' => 'some rowKey',
'columns' => [
'some int-col' => 10,
'some string-col' => 'string example',
'some json-col' => [
'test' => [
'foo' => 'nested'
]
],
'some array-col' => [
0,
1,
3,
4
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows"
payload := strings.NewReader("{\n \"items\": [\n {\n \"key\": \"some rowKey\",\n \"columns\": {\n \"some int-col\": 10,\n \"some string-col\": \"string example\",\n \"some json-col\": {\n \"test\": {\n \"foo\": \"nested\"\n }\n },\n \"some array-col\": [\n 0,\n 1,\n 3,\n 4\n ]\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"items\": [\n {\n \"key\": \"some rowKey\",\n \"columns\": {\n \"some int-col\": 10,\n \"some string-col\": \"string example\",\n \"some json-col\": {\n \"test\": {\n \"foo\": \"nested\"\n }\n },\n \"some array-col\": [\n 0,\n 1,\n 3,\n 4\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{}{
"code": 400,
"message": "<string>",
"missingFields": [
{}
]
}Authorizations
oidc-tokenoauth2-client-credentialsoauth2-open-industrial-dataoauth2-auth-code
Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.
Scopes
Path Parameters
Response
Empty response.
The response is of type object.
⌘I
JavaScript SDK
await client.raw.insertRows('My company', 'Customers', [{ key: 'customer1', columns: { 'First name': 'Steve', 'Last name': 'Jobs' } }]);from cognite.client.data_classes import RowWrite
rows = [RowWrite(key="r1", columns={"col1": "val1", "col2": "val1"}),
RowWrite(key="r2", columns={"col1": "val2", "col2": "val2"})]
client.raw.rows.insert("db1", "table1", rows)
rows = {
"key-1": {"col1": 1, "col2": 2},
"key-2": {"col1": 3, "col2": 4, "col3": "high five"},
}
client.raw.rows.insert("db1", "table1", rows)
import pandas as pd
df = pd.DataFrame(
{"col-a": [1, 3, None], "col-b": [2, -1, 9]},
index=["r1", "r2", "r3"])
res = client.raw.rows.insert_dataframe(
"db1", "table1", df, dropna=True)
List<RawRow> createRowsList = List.of(RawRow.newBuilder()
.setDbName("dbName")
.setTableName("tableName")
.setKey("key")
.setColumns(Struct.newBuilder()
.putFields("string", Values.of("VAL"))
.putFields("numeric", Values.of("VAL"))
.putFields("bool", Values.of(ThreadLocalRandom.current().nextBoolean()))
.putFields("null_value", Values.ofNull())
.putFields("array", Values.of(ListValue.newBuilder()
.addValues(Values.of(ThreadLocalRandom.current().nextDouble(10000d)))
.build()))
.putFields("struct", Values.of(Structs.of("nestedString", Values.of("myTrickyStringValue")
)))
).build());
List<RawRow> createRowsResults = client.raw().rows().upsert(createRowsList, false);
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"key": "some rowKey",
"columns": {
"some int-col": 10,
"some string-col": "string example",
"some json-col": {
"test": {
"foo": "nested"
}
},
"some array-col": [
0,
1,
3,
4
]
}
}
]
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'key' => 'some rowKey',
'columns' => [
'some int-col' => 10,
'some string-col' => 'string example',
'some json-col' => [
'test' => [
'foo' => 'nested'
]
],
'some array-col' => [
0,
1,
3,
4
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows"
payload := strings.NewReader("{\n \"items\": [\n {\n \"key\": \"some rowKey\",\n \"columns\": {\n \"some int-col\": 10,\n \"some string-col\": \"string example\",\n \"some json-col\": {\n \"test\": {\n \"foo\": \"nested\"\n }\n },\n \"some array-col\": [\n 0,\n 1,\n 3,\n 4\n ]\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/raw/dbs/{dbName}/tables/{tableName}/rows")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"items\": [\n {\n \"key\": \"some rowKey\",\n \"columns\": {\n \"some int-col\": 10,\n \"some string-col\": \"string example\",\n \"some json-col\": {\n \"test\": {\n \"foo\": \"nested\"\n }\n },\n \"some array-col\": [\n 0,\n 1,\n 3,\n 4\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{}{
"code": 400,
"message": "<string>",
"missingFields": [
{}
]
}