Chilkat Online Tools

SQL Server / Cognite API v1 / Filter time series

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": "consectetur reprehenderit",
    --     "unit": "voluptate occaecat ut dolor ",
    --     "isString": true,
    --     "isStep": false,
    --     "metadata": {},
    --     "assetIds": [
    --       2509118978120224,
    --       7226404981552392
    --     ],
    --     "assetExternalIds": [
    --       "est laborum",
    --       "in in et aliquip"
    --     ],
    --     "rootAssetIds": [
    --       6708483845679534,
    --       3834273847268414
    --     ],
    --     "assetSubtreeIds": [
    --       {
    --         "id": 4838322974326730
    --       },
    --       {
    --         "externalId": "nisi Excepteur exercitation nulla reprehenderit"
    --       }
    --     ],
    --     "dataSetIds": [
    --       {
    --         "externalId": "Ut ex consectetur"
    --       },
    --       {
    --         "id": 8956424920459844
    --       }
    --     ],
    --     "externalIdPrefix": "reprehenderit fugiat pariatur id culpa",
    --     "createdTime": {
    --       "max": 82460819,
    --       "min": 76400255
    --     },
    --     "lastUpdatedTime": {
    --       "max": 24839160,
    --       "min": 94565958
    --     }
    --   },
    --   "limit": 100,
    --   "cursor": "pariatur quis eu anim",
    --   "partition": "do amet consectetur ad f"
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.name', 'consectetur reprehenderit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.unit', 'voluptate occaecat ut dolor '
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.isString', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'filter.isStep', 0
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'filter.metadata'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[0]', 2509118978120224
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[1]', 7226404981552392
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[0]', 'est laborum'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[1]', 'in in et aliquip'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[0]', 6708483845679534
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[1]', 3834273847268414
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetSubtreeIds[1].externalId', 'nisi Excepteur exercitation nulla reprehenderit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[0].externalId', 'Ut ex consectetur'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.dataSetIds[1].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'reprehenderit fugiat pariatur id culpa'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 82460819
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 76400255
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 24839160
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 94565958
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'limit', 100
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'cursor', 'pariatur quis eu anim'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'partition', 'do amet consectetur ad f'

    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}}/timeseries/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": "consectetur reprehenderit",
        "unit": "voluptate occaecat ut dolor ",
        "isString": true,
        "isStep": false,
        "metadata": {},
        "assetIds": [
            2509118978120224,
            7226404981552392
        ],
        "assetExternalIds": [
            "est laborum",
            "in in et aliquip"
        ],
        "rootAssetIds": [
            6708483845679534,
            3834273847268414
        ],
        "assetSubtreeIds": [
            {
                "id": 4838322974326730
            },
            {
                "externalId": "nisi Excepteur exercitation nulla reprehenderit"
            }
        ],
        "dataSetIds": [
            {
                "externalId": "Ut ex consectetur"
            },
            {
                "id": 8956424920459844
            }
        ],
        "externalIdPrefix": "reprehenderit fugiat pariatur id culpa",
        "createdTime": {
            "max": 82460819,
            "min": 76400255
        },
        "lastUpdatedTime": {
            "max": 24839160,
            "min": 94565958
        }
    },
    "limit": 100,
    "cursor": "pariatur quis eu anim",
    "partition": "do amet consectetur ad f"
}'
https://domain.com/api/v1/projects/{{project}}/timeseries/list

Postman Collection Item JSON

{
  "id": "listTimeSeries",
  "name": "Filter time series",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "timeseries",
        "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": "Retrieves a list of time series matching the specified criteria. This operation supports pagination by cursor. Criteria can be applied to select a subset of time series.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"consectetur reprehenderit\",\n        \"unit\": \"voluptate occaecat ut dolor \",\n        \"isString\": true,\n        \"isStep\": false,\n        \"metadata\": {},\n        \"assetIds\": [\n            2509118978120224,\n            7226404981552392\n        ],\n        \"assetExternalIds\": [\n            \"est laborum\",\n            \"in in et aliquip\"\n        ],\n        \"rootAssetIds\": [\n            6708483845679534,\n            3834273847268414\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 4838322974326730\n            },\n            {\n                \"externalId\": \"nisi Excepteur exercitation nulla reprehenderit\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"externalId\": \"Ut ex consectetur\"\n            },\n            {\n                \"id\": 8956424920459844\n            }\n        ],\n        \"externalIdPrefix\": \"reprehenderit fugiat pariatur id culpa\",\n        \"createdTime\": {\n            \"max\": 82460819,\n            \"min\": 76400255\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 24839160,\n            \"min\": 94565958\n        }\n    },\n    \"limit\": 100,\n    \"cursor\": \"pariatur quis eu anim\",\n    \"partition\": \"do amet consectetur ad f\"\n}"
    }
  }
}