SQL Server / Cognite API v1 / Aggregate assets
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "filter": {
-- "name": "tempor in",
-- "parentIds": [
-- 2218036985580300,
-- 1325609532768832
-- ],
-- "parentExternalIds": [
-- "proident magna occaecat id",
-- "elit sint in"
-- ],
-- "rootIds": [
-- {
-- "id": 2434556236080026
-- },
-- {
-- "id": 3030224117188012
-- }
-- ],
-- "assetSubtreeIds": [
-- {
-- "id": 5500566008705236
-- },
-- {
-- "externalId": "magna pariatur ullamco aute"
-- }
-- ],
-- "dataSetIds": [
-- {
-- "externalId": "magna mollit eiusmod"
-- },
-- {
-- "externalId": "nulla tempor consectetur occaecat sit"
-- }
-- ],
-- "metadata": {},
-- "source": "quis",
-- "createdTime": {
-- "max": 51644802,
-- "min": 78848688
-- },
-- "lastUpdatedTime": {
-- "max": 42756152,
-- "min": 67449504
-- },
-- "root": false,
-- "externalIdPrefix": "aute officia sint nisi",
-- "labels": {
-- "containsAny": [
-- {
-- "externalId": "quis"
-- },
-- {
-- "externalId": "ex tempor"
-- }
-- ]
-- }
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.name', 'tempor in'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.parentIds[0]', 2218036985580300
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.parentIds[1]', 1325609532768832
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.parentExternalIds[0]', 'proident magna occaecat id'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.parentExternalIds[1]', 'elit sint in'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootIds[0].id', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootIds[1].id', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[0].id', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetSubtreeIds[1].externalId', 'magna pariatur ullamco aute'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[0].externalId', 'magna mollit eiusmod'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[1].externalId', 'nulla tempor consectetur occaecat sit'
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.source', 'quis'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 51644802
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 78848688
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 42756152
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 67449504
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.root', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'aute officia sint nisi'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAny[0].externalId', 'quis'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAny[1].externalId', 'ex tempor'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'api-key', '{{api-key}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/projects/{{project}}/assets/aggregate', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
Curl Command
curl -X POST
-H "api-key: {{api-key}}"
-H "content-type: application/json"
-d '{
"filter": {
"name": "tempor in",
"parentIds": [
2218036985580300,
1325609532768832
],
"parentExternalIds": [
"proident magna occaecat id",
"elit sint in"
],
"rootIds": [
{
"id": 2434556236080026
},
{
"id": 3030224117188012
}
],
"assetSubtreeIds": [
{
"id": 5500566008705236
},
{
"externalId": "magna pariatur ullamco aute"
}
],
"dataSetIds": [
{
"externalId": "magna mollit eiusmod"
},
{
"externalId": "nulla tempor consectetur occaecat sit"
}
],
"metadata": {},
"source": "quis",
"createdTime": {
"max": 51644802,
"min": 78848688
},
"lastUpdatedTime": {
"max": 42756152,
"min": 67449504
},
"root": false,
"externalIdPrefix": "aute officia sint nisi",
"labels": {
"containsAny": [
{
"externalId": "quis"
},
{
"externalId": "ex tempor"
}
]
}
}
}'
https://domain.com/api/v1/projects/{{project}}/assets/aggregate
Postman Collection Item JSON
{
"id": "aggregateAssets",
"name": "Aggregate assets",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"assets",
"aggregate"
],
"query": [
],
"variable": [
]
},
"method": "POST",
"header": [
{
"key": "api-key",
"value": "{{api-key}}",
"description": "An admin can create API keys in the Cognite console."
},
{
"key": "content-type",
"value": "application/json"
}
],
"description": "Use advanced filtering options to agggregate assets.",
"body": {
"mode": "raw",
"raw": "{\n \"filter\": {\n \"name\": \"tempor in\",\n \"parentIds\": [\n 2218036985580300,\n 1325609532768832\n ],\n \"parentExternalIds\": [\n \"proident magna occaecat id\",\n \"elit sint in\"\n ],\n \"rootIds\": [\n {\n \"id\": 2434556236080026\n },\n {\n \"id\": 3030224117188012\n }\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 5500566008705236\n },\n {\n \"externalId\": \"magna pariatur ullamco aute\"\n }\n ],\n \"dataSetIds\": [\n {\n \"externalId\": \"magna mollit eiusmod\"\n },\n {\n \"externalId\": \"nulla tempor consectetur occaecat sit\"\n }\n ],\n \"metadata\": {},\n \"source\": \"quis\",\n \"createdTime\": {\n \"max\": 51644802,\n \"min\": 78848688\n },\n \"lastUpdatedTime\": {\n \"max\": 42756152,\n \"min\": 67449504\n },\n \"root\": false,\n \"externalIdPrefix\": \"aute officia sint nisi\",\n \"labels\": {\n \"containsAny\": [\n {\n \"externalId\": \"quis\"\n },\n {\n \"externalId\": \"ex tempor\"\n }\n ]\n }\n }\n}"
}
}
}