const relationships = await client.relationships.retrieve([{externalId: 'abc'}, {externalId: 'def'}]);res = client.relationships.retrieve_multiple(external_ids=["abc", "def"])List<Item> byExternalIds = List.of(Item.newBuilder()
.setExternalId("10")
.build());
List<Relationship> list =
client.relationships().retrieve(byExternalIds);//by list of items
List<Relationship> list =
client.relationships().retrieve("10", "20");//by varargs of String
List<Item> byInternalIds = List.of(Item.newBuilder()
.setId(10)
.build());
List<Relationship> list =
client.relationships().retrieve(byInternalIds, true);//by list of items
List<Relationship> list1 =
client.relationships().retrieve(10,20);//by varargs of Longcurl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/byids \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"externalId": "<string>"
}
],
"ignoreUnknownIds": false,
"fetchResources": false
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/byids",
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>'
]
],
'ignoreUnknownIds' => false,
'fetchResources' => false
]),
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/byids"
payload := strings.NewReader("{\n \"items\": [\n {\n \"externalId\": \"<string>\"\n }\n ],\n \"ignoreUnknownIds\": false,\n \"fetchResources\": false\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/byids")
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 }\n ],\n \"ignoreUnknownIds\": false,\n \"fetchResources\": false\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"
}
],
"source": {
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"rootId": 4503599627370496,
"name": "<string>",
"id": 4503599627370496,
"aggregates": {
"childCount": 1,
"depth": 1,
"path": [
{
"id": 4503599627370496
}
]
},
"parentId": 4503599627370496,
"parentExternalId": "my.known.id",
"externalId": "my.known.id",
"description": "<string>",
"dataSetId": 4503599627370496,
"metadata": {},
"source": "<string>",
"labels": [
{
"externalId": "my.known.id"
}
],
"geoLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
123
]
},
"properties": {}
}
},
"target": {
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"rootId": 4503599627370496,
"name": "<string>",
"id": 4503599627370496,
"aggregates": {
"childCount": 1,
"depth": 1,
"path": [
{
"id": 4503599627370496
}
]
},
"parentId": 4503599627370496,
"parentExternalId": "my.known.id",
"externalId": "my.known.id",
"description": "<string>",
"dataSetId": 4503599627370496,
"metadata": {},
"source": "<string>",
"labels": [
{
"externalId": "my.known.id"
}
],
"geoLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
123
]
},
"properties": {}
}
}
}
]
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}{
"error": {
"code": 409,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Retrieve relationships
Required capabilities:
relationshipsAcl:READ
Retrieve relationships by external IDs. You can retrieve a maximum of 1000 relationships per request. The order of the relationships in the response equals the order in the request.
const relationships = await client.relationships.retrieve([{externalId: 'abc'}, {externalId: 'def'}]);res = client.relationships.retrieve_multiple(external_ids=["abc", "def"])List<Item> byExternalIds = List.of(Item.newBuilder()
.setExternalId("10")
.build());
List<Relationship> list =
client.relationships().retrieve(byExternalIds);//by list of items
List<Relationship> list =
client.relationships().retrieve("10", "20");//by varargs of String
List<Item> byInternalIds = List.of(Item.newBuilder()
.setId(10)
.build());
List<Relationship> list =
client.relationships().retrieve(byInternalIds, true);//by list of items
List<Relationship> list1 =
client.relationships().retrieve(10,20);//by varargs of Longcurl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/byids \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"externalId": "<string>"
}
],
"ignoreUnknownIds": false,
"fetchResources": false
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/relationships/byids",
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>'
]
],
'ignoreUnknownIds' => false,
'fetchResources' => false
]),
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/byids"
payload := strings.NewReader("{\n \"items\": [\n {\n \"externalId\": \"<string>\"\n }\n ],\n \"ignoreUnknownIds\": false,\n \"fetchResources\": false\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/byids")
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 }\n ],\n \"ignoreUnknownIds\": false,\n \"fetchResources\": false\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"
}
],
"source": {
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"rootId": 4503599627370496,
"name": "<string>",
"id": 4503599627370496,
"aggregates": {
"childCount": 1,
"depth": 1,
"path": [
{
"id": 4503599627370496
}
]
},
"parentId": 4503599627370496,
"parentExternalId": "my.known.id",
"externalId": "my.known.id",
"description": "<string>",
"dataSetId": 4503599627370496,
"metadata": {},
"source": "<string>",
"labels": [
{
"externalId": "my.known.id"
}
],
"geoLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
123
]
},
"properties": {}
}
},
"target": {
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"rootId": 4503599627370496,
"name": "<string>",
"id": 4503599627370496,
"aggregates": {
"childCount": 1,
"depth": 1,
"path": [
{
"id": 4503599627370496
}
]
},
"parentId": 4503599627370496,
"parentExternalId": "my.known.id",
"externalId": "my.known.id",
"description": "<string>",
"dataSetId": 4503599627370496,
"metadata": {},
"source": "<string>",
"labels": [
{
"externalId": "my.known.id"
}
],
"geoLocation": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
123
]
},
"properties": {}
}
}
}
]
}{
"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 list relationships.
1 - 1000 elementsShow child attributes
Show child attributes
Ignore external IDs that are not found.
If true, will try to fetch the resources referred to in the relationship, based on the users access rights. Will silently fail to attatch the resources if the user lacks access to some of them.
Response
Relationships stored by CDF.
1 - 1000 elementsShow child attributes
Show child attributes
Was this page helpful?