Synthetic query
Required capabilities:
dataModelsAcl:READdataModelInstancesAcl:READ
Execute an on-the-fly synthetic query
Scope dataModelsAcl:READ to the cdf_cdm space, and dataModelInstancesAcl to the spaces of the time series.
timeSeriesAcl:READ also works, but it’s deprecated.
POST
/
timeseries
/
synthetic
/
query
JavaScript SDK
await client.timeseries.syntheticQuery([
{
expression: "24 * TS{externalId='production/hour', aggregate='average', granularity='1d'}",
start: '48h-ago',
end: 'now',
limit: 100
}
]);expression = '''
123
+ ts{id:123}
+ ts{externalId:'abc'}
+ ts{space:'my-space',externalId:'my-ts-xid'}
'''
dps = client.time_series.data.synthetic.query(
expressions=expression,
start="2w-ago",
end="now")
from cognite.client.data_classes.data_modeling.ids import NodeId
ts = client.time_series.retrieve(id=123)
variables = {
"A": ts,
"B": "my_ts_external_id",
"C": NodeId("my-space", "my-ts-xid"),
}
dps = client.time_series.data.synthetic.query(
expressions="A+B+C", start="2w-ago", end="now", variables=variables)
from sympy import symbols, cos, sin
x, y = symbols("x y")
dps = client.time_series.data.synthetic.query(
[sin(x), y*cos(x)],
start="2w-ago",
end="now",
variables={x: "foo", y: "bar"},
aggregate="interpolation",
granularity="15m",
target_unit="temperature:deg_c")
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"items": [
{
"expression": "(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}",
"start": 0,
"end": 123,
"limit": 100,
"timeZone": "Europe/Oslo or UTC+05:30"
}
]
}
EOF<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/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([
'items' => [
[
'expression' => '(5 + TS{space=\'foo\', externalId=\'bar\'}) / TS{space=\'foo\', externalId=\'baz\', aggregate=\'average\', granularity=\'1h\'}',
'start' => 0,
'end' => 123,
'limit' => 100,
'timeZone' => 'Europe/Oslo or UTC+05:30'
]
]
]),
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}/timeseries/synthetic/query"
payload := strings.NewReader("{\n \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/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 \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"datapoints": [
{
"timestamp": 1730204346000,
"value": 123
}
],
"isString": false
}
]
}{
"error": {
"code": 403,
"message": "<string>",
"forbidden": [
{
"instanceId": {
"space": "<string>",
"externalId": "<string>"
}
}
]
}
}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
The list of queries to perform
⌘I
JavaScript SDK
await client.timeseries.syntheticQuery([
{
expression: "24 * TS{externalId='production/hour', aggregate='average', granularity='1d'}",
start: '48h-ago',
end: 'now',
limit: 100
}
]);expression = '''
123
+ ts{id:123}
+ ts{externalId:'abc'}
+ ts{space:'my-space',externalId:'my-ts-xid'}
'''
dps = client.time_series.data.synthetic.query(
expressions=expression,
start="2w-ago",
end="now")
from cognite.client.data_classes.data_modeling.ids import NodeId
ts = client.time_series.retrieve(id=123)
variables = {
"A": ts,
"B": "my_ts_external_id",
"C": NodeId("my-space", "my-ts-xid"),
}
dps = client.time_series.data.synthetic.query(
expressions="A+B+C", start="2w-ago", end="now", variables=variables)
from sympy import symbols, cos, sin
x, y = symbols("x y")
dps = client.time_series.data.synthetic.query(
[sin(x), y*cos(x)],
start="2w-ago",
end="now",
variables={x: "foo", y: "bar"},
aggregate="interpolation",
granularity="15m",
target_unit="temperature:deg_c")
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"items": [
{
"expression": "(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}",
"start": 0,
"end": 123,
"limit": 100,
"timeZone": "Europe/Oslo or UTC+05:30"
}
]
}
EOF<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/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([
'items' => [
[
'expression' => '(5 + TS{space=\'foo\', externalId=\'bar\'}) / TS{space=\'foo\', externalId=\'baz\', aggregate=\'average\', granularity=\'1h\'}',
'start' => 0,
'end' => 123,
'limit' => 100,
'timeZone' => 'Europe/Oslo or UTC+05:30'
]
]
]),
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}/timeseries/synthetic/query"
payload := strings.NewReader("{\n \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\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))
}HttpResponse<String> response = Unirest.post("https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/query")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/timeseries/synthetic/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 \"items\": [\n {\n \"expression\": \"(5 + TS{space='foo', externalId='bar'}) / TS{space='foo', externalId='baz', aggregate='average', granularity='1h'}\",\n \"start\": 0,\n \"end\": 123,\n \"limit\": 100,\n \"timeZone\": \"Europe/Oslo or UTC+05:30\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"datapoints": [
{
"timestamp": 1730204346000,
"value": 123
}
],
"isString": false
}
]
}{
"error": {
"code": 403,
"message": "<string>",
"forbidden": [
{
"instanceId": {
"space": "<string>",
"externalId": "<string>"
}
}
]
}
}