Chilkat Online Tools

SQL Server / Cognite API v1 / Filter 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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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": "reprehenderit consequat cupidatat",
    --     "parentIds": [
    --       3870116243090848,
    --       5438517294961442
    --     ],
    --     "parentExternalIds": [
    --       "tempor dolore adipisicing enim magna",
    --       "sed cillum aliqua irure n"
    --     ],
    --     "rootIds": [
    --       {
    --         "id": 3609316313824286
    --       },
    --       {
    --         "externalId": "enim ut"
    --       }
    --     ],
    --     "assetSubtreeIds": [
    --       {
    --         "id": 4152225494743294
    --       },
    --       {
    --         "id": 3214092498108058
    --       }
    --     ],
    --     "dataSetIds": [
    --       {
    --         "externalId": "do"
    --       },
    --       {
    --         "id": 7983266347295368
    --       }
    --     ],
    --     "metadata": {},
    --     "source": "occaecat incididunt cupidatat",
    --     "createdTime": {
    --       "max": 93577224,
    --       "min": 18146228
    --     },
    --     "lastUpdatedTime": {
    --       "max": 72464336,
    --       "min": 16571729
    --     },
    --     "root": true,
    --     "externalIdPrefix": "veniam aliqua",
    --     "labels": {
    --       "containsAny": [
    --         {
    --           "externalId": "in Lorem consequat"
    --         },
    --         {
    --           "externalId": "ut enim eu"
    --         }
    --       ]
    --     }
    --   },
    --   "limit": 100,
    --   "cursor": "elit laborum cillum",
    --   "aggregatedProperties": [
    --   ],
    --   "partition": "ea"
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.name', 'reprehenderit consequat cupidatat'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.parentIds[0]', 3870116243090848
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.parentIds[1]', 5438517294961442
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.parentExternalIds[0]', 'tempor dolore adipisicing enim magna'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.parentExternalIds[1]', 'sed cillum aliqua irure n'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.rootIds[1].externalId', 'enim ut'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[0].externalId', 'do'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.dataSetIds[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.source', 'occaecat incididunt cupidatat'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 93577224
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 18146228
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 72464336
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 16571729
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.root', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'veniam aliqua'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAny[0].externalId', 'in Lorem consequat'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.labels.containsAny[1].externalId', 'ut enim eu'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'limit', 100
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'cursor', 'elit laborum cillum'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'aggregatedProperties'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'partition', 'ea'

    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/list', '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": "reprehenderit consequat cupidatat",
        "parentIds": [
            3870116243090848,
            5438517294961442
        ],
        "parentExternalIds": [
            "tempor dolore adipisicing enim magna",
            "sed cillum aliqua irure n"
        ],
        "rootIds": [
            {
                "id": 3609316313824286
            },
            {
                "externalId": "enim ut"
            }
        ],
        "assetSubtreeIds": [
            {
                "id": 4152225494743294
            },
            {
                "id": 3214092498108058
            }
        ],
        "dataSetIds": [
            {
                "externalId": "do"
            },
            {
                "id": 7983266347295368
            }
        ],
        "metadata": {},
        "source": "occaecat incididunt cupidatat",
        "createdTime": {
            "max": 93577224,
            "min": 18146228
        },
        "lastUpdatedTime": {
            "max": 72464336,
            "min": 16571729
        },
        "root": true,
        "externalIdPrefix": "veniam aliqua",
        "labels": {
            "containsAny": [
                {
                    "externalId": "in Lorem consequat"
                },
                {
                    "externalId": "ut enim eu"
                }
            ]
        }
    },
    "limit": 100,
    "cursor": "elit laborum cillum",
    "aggregatedProperties": [],
    "partition": "ea"
}'
https://domain.com/api/v1/projects/{{project}}/assets/list

Postman Collection Item JSON

{
  "id": "listAssets",
  "name": "Filter assets",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "assets",
        "list"
      ],
      "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 find assets.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"reprehenderit consequat cupidatat\",\n        \"parentIds\": [\n            3870116243090848,\n            5438517294961442\n        ],\n        \"parentExternalIds\": [\n            \"tempor dolore adipisicing enim magna\",\n            \"sed cillum aliqua irure n\"\n        ],\n        \"rootIds\": [\n            {\n                \"id\": 3609316313824286\n            },\n            {\n                \"externalId\": \"enim ut\"\n            }\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 4152225494743294\n            },\n            {\n                \"id\": 3214092498108058\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"do\"\n            },\n            {\n                \"id\": 7983266347295368\n            }\n        ],\n        \"metadata\": {},\n        \"source\": \"occaecat incididunt cupidatat\",\n        \"createdTime\": {\n            \"max\": 93577224,\n            \"min\": 18146228\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 72464336,\n            \"min\": 16571729\n        },\n        \"root\": true,\n        \"externalIdPrefix\": \"veniam aliqua\",\n        \"labels\": {\n            \"containsAny\": [\n                {\n                    \"externalId\": \"in Lorem consequat\"\n                },\n                {\n                    \"externalId\": \"ut enim eu\"\n                }\n            ]\n        }\n    },\n    \"limit\": 100,\n    \"cursor\": \"elit laborum cillum\",\n    \"aggregatedProperties\": [],\n    \"partition\": \"ea\"\n}"
    }
  }
}