from cognite.client.data_classes.data_modeling.query import Query, Select, NodeResultSetExpression, EdgeResultSetExpression, SourceSelector
from cognite.client.data_classes.filters import Range, Equals
from cognite.client.data_classes.data_modeling.ids import ViewId
movie_id = ViewId("mySpace", "MovieView", "v1")
actor_id = ViewId("mySpace", "ActorView", "v1")
query = Query(
with_ = {
"movies": NodeResultSetExpression(filter=Range(movie_id.as_property_ref("releaseYear"), lt=2000)),
"actors_in_movie": EdgeResultSetExpression(from_="movies", filter=Equals(["edge", "type"], {"space": movie_id.space, "externalId": "Movie.actors"})),
"actors": NodeResultSetExpression(from_="actors_in_movie"),
},
select = {
"actors": Select(
[SourceSelector(actor_id, ["name"])], sort=[InstanceSort(actor_id.as_property_ref("name"))]),
},
)
res = client.data_modeling.instances.query(query)
from cognite.client.data_classes.data_modeling.data_types import UnitReference, UnitSystemReference
selected_source = SourceSelector(
source=ViewId("my-space", "my-xid", "v1"),
properties=["f32_prop1", "f32_prop2", "f64_prop1", "f64_prop2"],
target_units=[
TargetUnit("f32_prop1", UnitReference("pressure:kilopa")),
TargetUnit("f32_prop2", UnitReference("pressure:barg")),
TargetUnit("f64_prop1", UnitSystemReference("SI")),
TargetUnit("f64_prop2", UnitSystemReference("Imperial")),
],
)
SourceSelector(source=ViewId("my-space", "my-xid", "v1"), properties=["*"])curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"with": {},
"select": {},
"cursors": {},
"parameters": {},
"includeTyping": false,
"debug": {
"emitResults": true,
"timeout": 123,
"profile": false
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
with: {},
select: {},
cursors: {},
parameters: {},
includeTyping: false,
debug: {emitResults: true, timeout: 123, profile: false}
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query', 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/query",
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([
'with' => [
],
'select' => [
],
'cursors' => [
],
'parameters' => [
],
'includeTyping' => false,
'debug' => [
'emitResults' => true,
'timeout' => 123,
'profile' => 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/query"
payload := strings.NewReader("{\n \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query")
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 \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\n }\n}"
response = http.request(request)
puts response.read_body{
"items": {},
"nextCursor": {},
"typing": {},
"debug": {
"notices": [
{
"code": "excessiveTimeout",
"category": "invalidDebugOptions",
"level": "warning",
"hint": "<string>",
"timeout": 123
}
]
}
}{
"error": {
"code": 401,
"message": "Could not authenticate.",
"missing": [
{}
],
"duplicated": [
{}
]
}
}Query nodes/edges
Required capabilities:
dataModelsAcl:READ
Specification of query endpoint. For more information, see Query language.
from cognite.client.data_classes.data_modeling.query import Query, Select, NodeResultSetExpression, EdgeResultSetExpression, SourceSelector
from cognite.client.data_classes.filters import Range, Equals
from cognite.client.data_classes.data_modeling.ids import ViewId
movie_id = ViewId("mySpace", "MovieView", "v1")
actor_id = ViewId("mySpace", "ActorView", "v1")
query = Query(
with_ = {
"movies": NodeResultSetExpression(filter=Range(movie_id.as_property_ref("releaseYear"), lt=2000)),
"actors_in_movie": EdgeResultSetExpression(from_="movies", filter=Equals(["edge", "type"], {"space": movie_id.space, "externalId": "Movie.actors"})),
"actors": NodeResultSetExpression(from_="actors_in_movie"),
},
select = {
"actors": Select(
[SourceSelector(actor_id, ["name"])], sort=[InstanceSort(actor_id.as_property_ref("name"))]),
},
)
res = client.data_modeling.instances.query(query)
from cognite.client.data_classes.data_modeling.data_types import UnitReference, UnitSystemReference
selected_source = SourceSelector(
source=ViewId("my-space", "my-xid", "v1"),
properties=["f32_prop1", "f32_prop2", "f64_prop1", "f64_prop2"],
target_units=[
TargetUnit("f32_prop1", UnitReference("pressure:kilopa")),
TargetUnit("f32_prop2", UnitReference("pressure:barg")),
TargetUnit("f64_prop1", UnitSystemReference("SI")),
TargetUnit("f64_prop2", UnitSystemReference("Imperial")),
],
)
SourceSelector(source=ViewId("my-space", "my-xid", "v1"), properties=["*"])curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"with": {},
"select": {},
"cursors": {},
"parameters": {},
"includeTyping": false,
"debug": {
"emitResults": true,
"timeout": 123,
"profile": false
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
with: {},
select: {},
cursors: {},
parameters: {},
includeTyping: false,
debug: {emitResults: true, timeout: 123, profile: false}
})
};
fetch('https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query', 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/query",
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([
'with' => [
],
'select' => [
],
'cursors' => [
],
'parameters' => [
],
'includeTyping' => false,
'debug' => [
'emitResults' => true,
'timeout' => 123,
'profile' => 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/query"
payload := strings.NewReader("{\n \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/models/instances/query")
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 \"with\": {},\n \"select\": {},\n \"cursors\": {},\n \"parameters\": {},\n \"includeTyping\": false,\n \"debug\": {\n \"emitResults\": true,\n \"timeout\": 123,\n \"profile\": false\n }\n}"
response = http.request(request)
puts response.read_body{
"items": {},
"nextCursor": {},
"typing": {},
"debug": {
"notices": [
{
"code": "excessiveTimeout",
"category": "invalidDebugOptions",
"level": "warning",
"hint": "<string>",
"timeout": 123
}
]
}
}{
"error": {
"code": 401,
"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
Query specification.
Show child attributes
Show child attributes
Select properties for each result set.
Show child attributes
Show child attributes
Cursors returned from the previous query request. These cursors match the result set expressions you specified in the with clause for the query.
Show child attributes
Show child attributes
Values in filters can be parameterised. Parameters are provided as part of the query object, and referenced in the filter itself.
Show child attributes
Show child attributes
Should we return property type information as part of the result?
Return query debug notices.
Show child attributes
Show child attributes
Response
Matching nodes and edges
Was this page helpful?