Filter assets
Lists assets that match a filter. This endpoint is for exploration. Requires assetsAcl:READ. See Advanced filtering.
const assets = await client.assets.list({ filter: { name: '21PT1019' } });from cognite.client.data_classes import filters
in_timezone = filters.Prefix(["metadata", "timezone"], "Europe")
res = client.assets.filter(filter=in_timezone, sort=("external_id", "asc"))
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty, SortableAssetProperty
in_timezone = filters.Prefix(AssetProperty.metadata_key("timezone"), "Europe")
res = client.assets.filter(
filter=in_timezone,
sort=(SortableAssetProperty.external_id, "asc"))
asset_list = client.assets.list(limit=5)
for asset in client.assets:
asset # do something with the asset
for asset_list in client.assets(chunk_size=2500):
asset_list # do something with the assets
from cognite.client.data_classes import LabelFilter
my_label_filter = LabelFilter(contains_all=["PUMP", "VERIFIED"])
asset_list = client.assets.list(labels=my_label_filter)
from cognite.client.data_classes import filters
in_timezone = filters.Prefix(["metadata", "timezone"], "Europe")
res = client.assets.list(advanced_filter=in_timezone, sort=("external_id", "asc"))
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty, SortableAssetProperty
in_timezone = filters.Prefix(AssetProperty.metadata_key("timezone"), "Europe")
res = client.assets.list(
advanced_filter=in_timezone,
sort=(SortableAssetProperty.external_id, "asc"))
from cognite.client.data_classes import filters
not_instrument_lvl5 = filters.And(
filters.ContainsAny("labels", ["Level5"]),
filters.Not(filters.ContainsAny("labels", ["Instrument"]))
)
res = client.assets.list(asset_subtree_ids=[123456], advanced_filter=not_instrument_lvl5)
List<Asset> listAssetsResults = new ArrayList<>();
client.assets()
.list()
.forEachRemaining(listAssetsResults::addAll);
client.assets()
.list(Request.create()
.withFilterParameter("source", "source"))
.forEachRemaining(listAssetsResults::addAll);
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/list \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filter": {
"name": "<string>",
"parentIds": [
4503599627370496
],
"parentExternalIds": [
"my.known.id"
],
"rootIds": [
{
"id": 4503599627370496
}
],
"assetSubtreeIds": [
{
"id": 4503599627370496
}
],
"dataSetIds": [
{
"id": 4503599627370496
}
],
"metadata": {},
"source": "<string>",
"createdTime": {
"max": 1,
"min": 1
},
"lastUpdatedTime": {
"max": 1,
"min": 1
},
"root": true,
"externalIdPrefix": "my.known.prefix",
"labels": {
"containsAny": [
{
"externalId": "my.known.id"
}
]
}
},
"advancedFilter": {
"and": "<array>"
},
"limit": 100,
"sort": [
{
"property": [
"createdTime"
],
"order": "desc"
},
{
"property": [
"metadata",
"customMetadataKey"
],
"nulls": "first"
}
],
"cursor": "4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo",
"aggregatedProperties": [],
"partition": "1/3"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/list",
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([
'filter' => [
'name' => '<string>',
'parentIds' => [
4503599627370496
],
'parentExternalIds' => [
'my.known.id'
],
'rootIds' => [
[
'id' => 4503599627370496
]
],
'assetSubtreeIds' => [
[
'id' => 4503599627370496
]
],
'dataSetIds' => [
[
'id' => 4503599627370496
]
],
'metadata' => [
],
'source' => '<string>',
'createdTime' => [
'max' => 1,
'min' => 1
],
'lastUpdatedTime' => [
'max' => 1,
'min' => 1
],
'root' => true,
'externalIdPrefix' => 'my.known.prefix',
'labels' => [
'containsAny' => [
[
'externalId' => 'my.known.id'
]
]
]
],
'advancedFilter' => [
'and' => '<array>'
],
'limit' => 100,
'sort' => [
[
'property' => [
'createdTime'
],
'order' => 'desc'
],
[
'property' => [
'metadata',
'customMetadataKey'
],
'nulls' => 'first'
]
],
'cursor' => '4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo',
'aggregatedProperties' => [
],
'partition' => '1/3'
]),
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}/assets/list"
payload := strings.NewReader("{\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n },\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"limit\": 100,\n \"sort\": [\n {\n \"property\": [\n \"createdTime\"\n ],\n \"order\": \"desc\"\n },\n {\n \"property\": [\n \"metadata\",\n \"customMetadataKey\"\n ],\n \"nulls\": \"first\"\n }\n ],\n \"cursor\": \"4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo\",\n \"aggregatedProperties\": [],\n \"partition\": \"1/3\"\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}/assets/list")
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 \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n },\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"limit\": 100,\n \"sort\": [\n {\n \"property\": [\n \"createdTime\"\n ],\n \"order\": \"desc\"\n },\n {\n \"property\": [\n \"metadata\",\n \"customMetadataKey\"\n ],\n \"nulls\": \"first\"\n }\n ],\n \"cursor\": \"4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo\",\n \"aggregatedProperties\": [],\n \"partition\": \"1/3\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"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": {}
}
}
],
"nextCursor": "<string>"
}{
"error": {
"code": 400,
"message": "`null` values aren't allowed."
}
}{
"error": {
"code": 429,
"message": "Project exceeded maximum number='50' of concurrent requests. Please try again later."
}
}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.
Scopes
Body
Cursor for paging through results. In general, if a response contains a nextCursor
property, it means that there may be more results, and you should pass that value as the
cursor parameter in the next request.
Note that the cursor may or may not be encrypted, but either way, it is not intended to be decoded. Its internal structure is not a part of the public API, and may change without notice. You should treat it as an opaque string and not attempt to craft your own cursors.
Splits the data set into N partitions.
The attribute is specified as a "M/N" string, where M is a natural number in the interval of [1, N].
You need to follow the cursors within each partition in order to receive all the data.
The maximum number of allowed partitions (N) is 10.
Cognite rejects requests if you specify more than 10 partitions. When Cognite enforces this behavior, the requests result in a 400 Bad Request status.
"1/3"
const assets = await client.assets.list({ filter: { name: '21PT1019' } });from cognite.client.data_classes import filters
in_timezone = filters.Prefix(["metadata", "timezone"], "Europe")
res = client.assets.filter(filter=in_timezone, sort=("external_id", "asc"))
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty, SortableAssetProperty
in_timezone = filters.Prefix(AssetProperty.metadata_key("timezone"), "Europe")
res = client.assets.filter(
filter=in_timezone,
sort=(SortableAssetProperty.external_id, "asc"))
asset_list = client.assets.list(limit=5)
for asset in client.assets:
asset # do something with the asset
for asset_list in client.assets(chunk_size=2500):
asset_list # do something with the assets
from cognite.client.data_classes import LabelFilter
my_label_filter = LabelFilter(contains_all=["PUMP", "VERIFIED"])
asset_list = client.assets.list(labels=my_label_filter)
from cognite.client.data_classes import filters
in_timezone = filters.Prefix(["metadata", "timezone"], "Europe")
res = client.assets.list(advanced_filter=in_timezone, sort=("external_id", "asc"))
from cognite.client.data_classes import filters
from cognite.client.data_classes.assets import AssetProperty, SortableAssetProperty
in_timezone = filters.Prefix(AssetProperty.metadata_key("timezone"), "Europe")
res = client.assets.list(
advanced_filter=in_timezone,
sort=(SortableAssetProperty.external_id, "asc"))
from cognite.client.data_classes import filters
not_instrument_lvl5 = filters.And(
filters.ContainsAny("labels", ["Level5"]),
filters.Not(filters.ContainsAny("labels", ["Instrument"]))
)
res = client.assets.list(asset_subtree_ids=[123456], advanced_filter=not_instrument_lvl5)
List<Asset> listAssetsResults = new ArrayList<>();
client.assets()
.list()
.forEachRemaining(listAssetsResults::addAll);
client.assets()
.list(Request.create()
.withFilterParameter("source", "source"))
.forEachRemaining(listAssetsResults::addAll);
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/list \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"filter": {
"name": "<string>",
"parentIds": [
4503599627370496
],
"parentExternalIds": [
"my.known.id"
],
"rootIds": [
{
"id": 4503599627370496
}
],
"assetSubtreeIds": [
{
"id": 4503599627370496
}
],
"dataSetIds": [
{
"id": 4503599627370496
}
],
"metadata": {},
"source": "<string>",
"createdTime": {
"max": 1,
"min": 1
},
"lastUpdatedTime": {
"max": 1,
"min": 1
},
"root": true,
"externalIdPrefix": "my.known.prefix",
"labels": {
"containsAny": [
{
"externalId": "my.known.id"
}
]
}
},
"advancedFilter": {
"and": "<array>"
},
"limit": 100,
"sort": [
{
"property": [
"createdTime"
],
"order": "desc"
},
{
"property": [
"metadata",
"customMetadataKey"
],
"nulls": "first"
}
],
"cursor": "4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo",
"aggregatedProperties": [],
"partition": "1/3"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/assets/list",
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([
'filter' => [
'name' => '<string>',
'parentIds' => [
4503599627370496
],
'parentExternalIds' => [
'my.known.id'
],
'rootIds' => [
[
'id' => 4503599627370496
]
],
'assetSubtreeIds' => [
[
'id' => 4503599627370496
]
],
'dataSetIds' => [
[
'id' => 4503599627370496
]
],
'metadata' => [
],
'source' => '<string>',
'createdTime' => [
'max' => 1,
'min' => 1
],
'lastUpdatedTime' => [
'max' => 1,
'min' => 1
],
'root' => true,
'externalIdPrefix' => 'my.known.prefix',
'labels' => [
'containsAny' => [
[
'externalId' => 'my.known.id'
]
]
]
],
'advancedFilter' => [
'and' => '<array>'
],
'limit' => 100,
'sort' => [
[
'property' => [
'createdTime'
],
'order' => 'desc'
],
[
'property' => [
'metadata',
'customMetadataKey'
],
'nulls' => 'first'
]
],
'cursor' => '4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo',
'aggregatedProperties' => [
],
'partition' => '1/3'
]),
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}/assets/list"
payload := strings.NewReader("{\n \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n },\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"limit\": 100,\n \"sort\": [\n {\n \"property\": [\n \"createdTime\"\n ],\n \"order\": \"desc\"\n },\n {\n \"property\": [\n \"metadata\",\n \"customMetadataKey\"\n ],\n \"nulls\": \"first\"\n }\n ],\n \"cursor\": \"4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo\",\n \"aggregatedProperties\": [],\n \"partition\": \"1/3\"\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}/assets/list")
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 \"filter\": {\n \"name\": \"<string>\",\n \"parentIds\": [\n 4503599627370496\n ],\n \"parentExternalIds\": [\n \"my.known.id\"\n ],\n \"rootIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"metadata\": {},\n \"source\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"root\": true,\n \"externalIdPrefix\": \"my.known.prefix\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"my.known.id\"\n }\n ]\n }\n },\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"limit\": 100,\n \"sort\": [\n {\n \"property\": [\n \"createdTime\"\n ],\n \"order\": \"desc\"\n },\n {\n \"property\": [\n \"metadata\",\n \"customMetadataKey\"\n ],\n \"nulls\": \"first\"\n }\n ],\n \"cursor\": \"4zj0Vy2fo0NtNMb229mI9r1V3YG5NBL752kQz1cKtwo\",\n \"aggregatedProperties\": [],\n \"partition\": \"1/3\"\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"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": {}
}
}
],
"nextCursor": "<string>"
}{
"error": {
"code": 400,
"message": "`null` values aren't allowed."
}
}{
"error": {
"code": 429,
"message": "Project exceeded maximum number='50' of concurrent requests. Please try again later."
}
}