rel = client.relationships.retrieve(external_id="flow1")
rel.confidence = 0.75
res = client.relationships.update(rel)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").source_external_id.set("alternate_source").confidence.set(0.97)
res1 = client.relationships.update(my_update)
another_update = RelationshipUpdate(external_id="flow_1").confidence.set(None)
res2 = client.relationships.update(another_update)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").labels.add(["PUMP", "VERIFIED"])
res = client.relationships.update(my_update)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").labels.remove("PUMP")
res = client.relationships.update(my_update)List<Relationship> relationshipList = // list of Relationship for update;
List<Relationship> upsertRelationshipsList =
client.relationships().upsert(relationshipList);curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"externalId": "<string>",
"update": {
"confidence": {
"set": 0.5
},
"startTime": {
"set": 1730204346000
},
"endTime": {
"set": 1730204346000
},
"dataSetId": {
"set": 4503599627370496
},
"labels": {
"add": [
{
"externalId": "my.known.id"
}
],
"remove": [
{
"externalId": "my.known.id"
}
]
}
}
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [
{
externalId: '<string>',
update: {
confidence: {set: 0.5},
startTime: {set: 1730204346000},
endTime: {set: 1730204346000},
dataSetId: {set: 4503599627370496},
labels: {add: [{externalId: 'my.known.id'}], remove: [{externalId: 'my.known.id'}]}
}
}
]
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update",
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' => [
[
'externalId' => '<string>',
'update' => [
'confidence' => [
'set' => 0.5
],
'startTime' => [
'set' => 1730204346000
],
'endTime' => [
'set' => 1730204346000
],
'dataSetId' => [
'set' => 4503599627370496
],
'labels' => [
'add' => [
[
'externalId' => 'my.known.id'
]
],
'remove' => [
[
'externalId' => 'my.known.id'
]
]
]
]
]
]
]),
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}/relationships/update"
payload := strings.NewReader("{\n \"items\": [\n {\n \"externalId\": \"<string>\",\n \"update\": {\n \"confidence\": {\n \"set\": 0.5\n },\n \"startTime\": {\n \"set\": 1730204346000\n },\n \"endTime\": {\n \"set\": 1730204346000\n },\n \"dataSetId\": {\n \"set\": 4503599627370496\n },\n \"labels\": {\n \"add\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ],\n \"remove\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\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}/relationships/update")
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 \"externalId\": \"<string>\",\n \"update\": {\n \"confidence\": {\n \"set\": 0.5\n },\n \"startTime\": {\n \"set\": 1730204346000\n },\n \"endTime\": {\n \"set\": 1730204346000\n },\n \"dataSetId\": {\n \"set\": 4503599627370496\n },\n \"labels\": {\n \"add\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ],\n \"remove\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"externalId": "<string>",
"sourceExternalId": "<string>",
"targetExternalId": "<string>",
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"startTime": 1730204346000,
"endTime": 1730204346000,
"confidence": 0.5,
"dataSetId": 4503599627370496,
"labels": [
{
"externalId": "my.known.id"
}
]
}
]
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Update relationships
Required capabilities:
relationshipsAcl:WRITErelationshipsAcl:READ
Update relationships between resources according to the partial definitions of the relationships given in the payload of the request. This means that fields not mentioned in the payload will remain unchanged. Up to 1000 relationships can be updated in one operation.
To delete a value from an optional value the setNull field should be set to true.
The order of the updated relationships in the response equals the order in the request.
rel = client.relationships.retrieve(external_id="flow1")
rel.confidence = 0.75
res = client.relationships.update(rel)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").source_external_id.set("alternate_source").confidence.set(0.97)
res1 = client.relationships.update(my_update)
another_update = RelationshipUpdate(external_id="flow_1").confidence.set(None)
res2 = client.relationships.update(another_update)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").labels.add(["PUMP", "VERIFIED"])
res = client.relationships.update(my_update)
from cognite.client.data_classes import RelationshipUpdate
my_update = RelationshipUpdate(external_id="flow_1").labels.remove("PUMP")
res = client.relationships.update(my_update)List<Relationship> relationshipList = // list of Relationship for update;
List<Relationship> upsertRelationshipsList =
client.relationships().upsert(relationshipList);curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"externalId": "<string>",
"update": {
"confidence": {
"set": 0.5
},
"startTime": {
"set": 1730204346000
},
"endTime": {
"set": 1730204346000
},
"dataSetId": {
"set": 4503599627370496
},
"labels": {
"add": [
{
"externalId": "my.known.id"
}
],
"remove": [
{
"externalId": "my.known.id"
}
]
}
}
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [
{
externalId: '<string>',
update: {
confidence: {set: 0.5},
startTime: {set: 1730204346000},
endTime: {set: 1730204346000},
dataSetId: {set: 4503599627370496},
labels: {add: [{externalId: 'my.known.id'}], remove: [{externalId: 'my.known.id'}]}
}
}
]
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/update",
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' => [
[
'externalId' => '<string>',
'update' => [
'confidence' => [
'set' => 0.5
],
'startTime' => [
'set' => 1730204346000
],
'endTime' => [
'set' => 1730204346000
],
'dataSetId' => [
'set' => 4503599627370496
],
'labels' => [
'add' => [
[
'externalId' => 'my.known.id'
]
],
'remove' => [
[
'externalId' => 'my.known.id'
]
]
]
]
]
]
]),
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}/relationships/update"
payload := strings.NewReader("{\n \"items\": [\n {\n \"externalId\": \"<string>\",\n \"update\": {\n \"confidence\": {\n \"set\": 0.5\n },\n \"startTime\": {\n \"set\": 1730204346000\n },\n \"endTime\": {\n \"set\": 1730204346000\n },\n \"dataSetId\": {\n \"set\": 4503599627370496\n },\n \"labels\": {\n \"add\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ],\n \"remove\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\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}/relationships/update")
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 \"externalId\": \"<string>\",\n \"update\": {\n \"confidence\": {\n \"set\": 0.5\n },\n \"startTime\": {\n \"set\": 1730204346000\n },\n \"endTime\": {\n \"set\": 1730204346000\n },\n \"dataSetId\": {\n \"set\": 4503599627370496\n },\n \"labels\": {\n \"add\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ],\n \"remove\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"externalId": "<string>",
"sourceExternalId": "<string>",
"targetExternalId": "<string>",
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"startTime": 1730204346000,
"endTime": 1730204346000,
"confidence": 0.5,
"dataSetId": 4503599627370496,
"labels": [
{
"externalId": "my.known.id"
}
]
}
]
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Authorizations
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.
Body
Data required to update relationships.
1 - 1000 elementsShow child attributes
Show child attributes
Response
Relationships stored by CDF.
1 - 1000 elementsShow child attributes
Show child attributes
Was this page helpful?