Retrieve nodes/edges by their external ids
Required capabilities:
dataModelsAcl:READ
Retrieve up to 1000 nodes or edges by their external ids.
POST
/
models
/
instances
/
byids
Python SDK
res = client.data_modeling.instances.retrieve(
nodes=("mySpace", "myNodeExternalId"),
edges=("mySpace", "myEdgeExternalId"),
sources=("mySpace", "myViewExternalId", "myViewVersion"))
from cognite.client.data_classes.data_modeling import NodeId, EdgeId, ViewId
res = client.data_modeling.instances.retrieve(
NodeId("mySpace", "myNode"),
EdgeId("mySpace", "myEdge"),
ViewId("mySpace", "myViewExternalId", "myViewVersion"))
from cognite.client.data_classes.data_modeling import NodeId, EdgeId
res = client.data_modeling.instances.retrieve(
NodeId("mySpace", "myNode"),
EdgeId("mySpace", "myEdge"),
sources=("myspace", "myView"))
from cognite.client.data_classes.data_modeling import EdgeId, TypedEdge, PropertyOptions, DirectRelationReference, ViewId
class Flow(TypedEdge):
flow_rate = PropertyOptions(identifier="flowRate")
def __init__(
self,
space: str,
external_id: str,
version: int,
type: DirectRelationReference,
last_updated_time: int,
created_time: int,
flow_rate: float,
start_node: DirectRelationReference,
end_node: DirectRelationReference,
deleted_time: int | None = None,
) -> None:
super().__init__(
space, external_id, version, type, last_updated_time, created_time, start_node, end_node, deleted_time
)
self.flow_rate = flow_rate
@classmethod
def get_source(cls) -> ViewId:
return ViewId("sp_model_space", "flow", "1")
res = client.data_modeling.instances.retrieve_edges(
EdgeId("mySpace", "theFlow"), edge_cls=Flow
)
isinstance(res, Flow)
from cognite.client.data_classes.data_modeling import NodeId, TypedNode, PropertyOptions, DirectRelationReference, ViewId
class Person(TypedNode):
birth_year = PropertyOptions(identifier="birthYear")
def __init__(
self,
space: str,
external_id: str,
version: int,
last_updated_time: int,
created_time: int,
name: str,
birth_year: int | None = None,
type: DirectRelationReference | None = None,
deleted_time: int | None = None,
):
super().__init__(
space=space,
external_id=external_id,
version=version,
last_updated_time=last_updated_time,
created_time=created_time,
type=type,
deleted_time=deleted_time
)
self.name = name
self.birth_year = birth_year
@classmethod
def get_source(cls) -> ViewId:
return ViewId("myModelSpace", "Person", "1")
res = client.data_modeling.instances.retrieve_nodes(
NodeId("myDataSpace", "myPerson"), node_cls=Person
)
isinstance(res, Person)curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"instanceType": "node",
"externalId": "<string>",
"space": "<string>"
}
],
"sources": [
{
"source": {
"type": "view",
"space": "<string>",
"externalId": "<string>",
"version": "<string>"
},
"targetUnits": [
{
"property": "<string>",
"unit": {
"externalId": "<string>"
}
}
]
}
],
"includeTyping": false
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [{instanceType: 'node', externalId: '<string>', space: '<string>'}],
sources: [
{
source: {type: 'view', space: '<string>', externalId: '<string>', version: '<string>'},
targetUnits: [{property: '<string>', unit: {externalId: '<string>'}}]
}
],
includeTyping: false
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids', 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}/models/instances/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' => [
[
'instanceType' => 'node',
'externalId' => '<string>',
'space' => '<string>'
]
],
'sources' => [
[
'source' => [
'type' => 'view',
'space' => '<string>',
'externalId' => '<string>',
'version' => '<string>'
],
'targetUnits' => [
[
'property' => '<string>',
'unit' => [
'externalId' => '<string>'
]
]
]
]
],
'includeTyping' => 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}/models/instances/byids"
payload := strings.NewReader("{\n \"items\": [\n {\n \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": 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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/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 \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": false\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"instanceType": "node",
"version": 123,
"space": "<string>",
"externalId": "<string>",
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"type": {
"space": "<string>",
"externalId": "<string>"
},
"deletedTime": 1730204346000,
"properties": {}
}
],
"typing": {}
}{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}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
Body
application/json
List of external-ids for nodes or edges to retrieve. Properties for up to 10 unique views (in total across the external ids requested) can be retrieved in one query.
⌘I
Python SDK
res = client.data_modeling.instances.retrieve(
nodes=("mySpace", "myNodeExternalId"),
edges=("mySpace", "myEdgeExternalId"),
sources=("mySpace", "myViewExternalId", "myViewVersion"))
from cognite.client.data_classes.data_modeling import NodeId, EdgeId, ViewId
res = client.data_modeling.instances.retrieve(
NodeId("mySpace", "myNode"),
EdgeId("mySpace", "myEdge"),
ViewId("mySpace", "myViewExternalId", "myViewVersion"))
from cognite.client.data_classes.data_modeling import NodeId, EdgeId
res = client.data_modeling.instances.retrieve(
NodeId("mySpace", "myNode"),
EdgeId("mySpace", "myEdge"),
sources=("myspace", "myView"))
from cognite.client.data_classes.data_modeling import EdgeId, TypedEdge, PropertyOptions, DirectRelationReference, ViewId
class Flow(TypedEdge):
flow_rate = PropertyOptions(identifier="flowRate")
def __init__(
self,
space: str,
external_id: str,
version: int,
type: DirectRelationReference,
last_updated_time: int,
created_time: int,
flow_rate: float,
start_node: DirectRelationReference,
end_node: DirectRelationReference,
deleted_time: int | None = None,
) -> None:
super().__init__(
space, external_id, version, type, last_updated_time, created_time, start_node, end_node, deleted_time
)
self.flow_rate = flow_rate
@classmethod
def get_source(cls) -> ViewId:
return ViewId("sp_model_space", "flow", "1")
res = client.data_modeling.instances.retrieve_edges(
EdgeId("mySpace", "theFlow"), edge_cls=Flow
)
isinstance(res, Flow)
from cognite.client.data_classes.data_modeling import NodeId, TypedNode, PropertyOptions, DirectRelationReference, ViewId
class Person(TypedNode):
birth_year = PropertyOptions(identifier="birthYear")
def __init__(
self,
space: str,
external_id: str,
version: int,
last_updated_time: int,
created_time: int,
name: str,
birth_year: int | None = None,
type: DirectRelationReference | None = None,
deleted_time: int | None = None,
):
super().__init__(
space=space,
external_id=external_id,
version=version,
last_updated_time=last_updated_time,
created_time=created_time,
type=type,
deleted_time=deleted_time
)
self.name = name
self.birth_year = birth_year
@classmethod
def get_source(cls) -> ViewId:
return ViewId("myModelSpace", "Person", "1")
res = client.data_modeling.instances.retrieve_nodes(
NodeId("myDataSpace", "myPerson"), node_cls=Person
)
isinstance(res, Person)curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"instanceType": "node",
"externalId": "<string>",
"space": "<string>"
}
],
"sources": [
{
"source": {
"type": "view",
"space": "<string>",
"externalId": "<string>",
"version": "<string>"
},
"targetUnits": [
{
"property": "<string>",
"unit": {
"externalId": "<string>"
}
}
]
}
],
"includeTyping": false
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
items: [{instanceType: 'node', externalId: '<string>', space: '<string>'}],
sources: [
{
source: {type: 'view', space: '<string>', externalId: '<string>', version: '<string>'},
targetUnits: [{property: '<string>', unit: {externalId: '<string>'}}]
}
],
includeTyping: false
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids', 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}/models/instances/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' => [
[
'instanceType' => 'node',
'externalId' => '<string>',
'space' => '<string>'
]
],
'sources' => [
[
'source' => [
'type' => 'view',
'space' => '<string>',
'externalId' => '<string>',
'version' => '<string>'
],
'targetUnits' => [
[
'property' => '<string>',
'unit' => [
'externalId' => '<string>'
]
]
]
]
],
'includeTyping' => 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}/models/instances/byids"
payload := strings.NewReader("{\n \"items\": [\n {\n \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": 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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/byids")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/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 \"instanceType\": \"node\",\n \"externalId\": \"<string>\",\n \"space\": \"<string>\"\n }\n ],\n \"sources\": [\n {\n \"source\": {\n \"type\": \"view\",\n \"space\": \"<string>\",\n \"externalId\": \"<string>\",\n \"version\": \"<string>\"\n },\n \"targetUnits\": [\n {\n \"property\": \"<string>\",\n \"unit\": {\n \"externalId\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"includeTyping\": false\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"instanceType": "node",
"version": 123,
"space": "<string>",
"externalId": "<string>",
"createdTime": 1730204346000,
"lastUpdatedTime": 1730204346000,
"type": {
"space": "<string>",
"externalId": "<string>"
},
"deletedTime": 1730204346000,
"properties": {}
}
],
"typing": {}
}{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}