Chilkat Online Tools

SQL Server / Cognite API v1 / Filter all events

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": {
    --     "startTime": {
    --       "max": 96423541,
    --       "min": 708508
    --     },
    --     "endTime": {
    --       "isNull": false
    --     },
    --     "activeAtTime": {
    --       "max": 42601793,
    --       "min": 6545191
    --     },
    --     "metadata": {},
    --     "assetIds": [
    --       5846331094676668,
    --       3408965310215146
    --     ],
    --     "assetExternalIds": [
    --       "deserunt aliquip Ut occaecat in",
    --       "non o"
    --     ],
    --     "rootAssetIds": [
    --       {
    --         "externalId": "veniam commodo minim Duis ut"
    --       },
    --       {
    --         "id": 2472341704760768
    --       }
    --     ],
    --     "assetSubtreeIds": [
    --       {
    --         "id": 6194248735806298
    --       },
    --       {
    --         "externalId": "adipisicing"
    --       }
    --     ],
    --     "dataSetIds": [
    --       {
    --         "externalId": "commodo nisi"
    --       },
    --       {
    --         "id": 4778982098206896
    --       }
    --     ],
    --     "source": "incididunt",
    --     "type": "in occaecat",
    --     "subtype": "dolore minim ipsum",
    --     "createdTime": {
    --       "max": 75538890,
    --       "min": 51111895
    --     },
    --     "lastUpdatedTime": {
    --       "max": 31243942,
    --       "min": 56817666
    --     },
    --     "externalIdPrefix": "cillum"
    --   },
    --   "limit": 100,
    --   "sort": [
    --   ],
    --   "cursor": "laborum officia ullamco e",
    --   "partition": "elit velit"
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.startTime.max', 96423541
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.startTime.min', 708508
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.endTime.isNull', 0
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.activeAtTime.max', 42601793
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.activeAtTime.min', 6545191
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[0]', 5846331094676668
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[1]', 3408965310215146
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[0]', 'deserunt aliquip Ut occaecat in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[1]', 'non o'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.rootAssetIds[0].externalId', 'veniam commodo minim Duis ut'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[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', 'adipisicing'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[0].externalId', 'commodo nisi'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.dataSetIds[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.source', 'incididunt'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.type', 'in occaecat'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.subtype', 'dolore minim ipsum'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 75538890
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 51111895
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 31243942
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 56817666
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'cillum'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'limit', 100
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'sort'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'cursor', 'laborum officia ullamco e'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'partition', 'elit velit'

    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}}/events/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": {
        "startTime": {
            "max": 96423541,
            "min": 708508
        },
        "endTime": {
            "isNull": false
        },
        "activeAtTime": {
            "max": 42601793,
            "min": 6545191
        },
        "metadata": {},
        "assetIds": [
            5846331094676668,
            3408965310215146
        ],
        "assetExternalIds": [
            "deserunt aliquip Ut occaecat in",
            "non o"
        ],
        "rootAssetIds": [
            {
                "externalId": "veniam commodo minim Duis ut"
            },
            {
                "id": 2472341704760768
            }
        ],
        "assetSubtreeIds": [
            {
                "id": 6194248735806298
            },
            {
                "externalId": "adipisicing"
            }
        ],
        "dataSetIds": [
            {
                "externalId": "commodo nisi"
            },
            {
                "id": 4778982098206896
            }
        ],
        "source": "incididunt",
        "type": "in occaecat",
        "subtype": "dolore minim ipsum",
        "createdTime": {
            "max": 75538890,
            "min": 51111895
        },
        "lastUpdatedTime": {
            "max": 31243942,
            "min": 56817666
        },
        "externalIdPrefix": "cillum"
    },
    "limit": 100,
    "sort": [],
    "cursor": "laborum officia ullamco e",
    "partition": "elit velit"
}'
https://domain.com/api/v1/projects/{{project}}/events/list

Postman Collection Item JSON

{
  "id": "advancedListEvents",
  "name": "Filter all events",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "events",
        "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": "Retrieve a list of all events in the same project. This operation supports pagination by cursor. Criteria can be applied to select a subset of events.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"startTime\": {\n            \"max\": 96423541,\n            \"min\": 708508\n        },\n        \"endTime\": {\n            \"isNull\": false\n        },\n        \"activeAtTime\": {\n            \"max\": 42601793,\n            \"min\": 6545191\n        },\n        \"metadata\": {},\n        \"assetIds\": [\n            5846331094676668,\n            3408965310215146\n        ],\n        \"assetExternalIds\": [\n            \"deserunt aliquip Ut occaecat in\",\n            \"non o\"\n        ],\n        \"rootAssetIds\": [\n            {\n                \"externalId\": \"veniam commodo minim Duis ut\"\n            },\n            {\n                \"id\": 2472341704760768\n            }\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 6194248735806298\n            },\n            {\n                \"externalId\": \"adipisicing\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"commodo nisi\"\n            },\n            {\n                \"id\": 4778982098206896\n            }\n        ],\n        \"source\": \"incididunt\",\n        \"type\": \"in occaecat\",\n        \"subtype\": \"dolore minim ipsum\",\n        \"createdTime\": {\n            \"max\": 75538890,\n            \"min\": 51111895\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 31243942,\n            \"min\": 56817666\n        },\n        \"externalIdPrefix\": \"cillum\"\n    },\n    \"limit\": 100,\n    \"sort\": [],\n    \"cursor\": \"laborum officia ullamco e\",\n    \"partition\": \"elit velit\"\n}"
    }
  }
}