Chilkat Online Tools

SQL Server / Cognite API v1 / Aggregate 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": "et exercitation s",
    --     "unit": "pariatur esse qui",
    --     "isString": true,
    --     "isStep": false,
    --     "metadata": {},
    --     "assetIds": [
    --       2274246036570026,
    --       8922483798410046
    --     ],
    --     "assetExternalIds": [
    --       "proident Ut consequat in",
    --       "elit incididunt aliqua"
    --     ],
    --     "rootAssetIds": [
    --       7714215516056826,
    --       4275780546438472
    --     ],
    --     "assetSubtreeIds": [
    --       {
    --         "id": 7555548287718054
    --       },
    --       {
    --         "externalId": "re"
    --       }
    --     ],
    --     "dataSetIds": [
    --       {
    --         "id": 5946532482497628
    --       },
    --       {
    --         "externalId": "exercitation nisi elit"
    --       }
    --     ],
    --     "externalIdPrefix": "aute Ut nostrud commodo in",
    --     "createdTime": {
    --       "max": 16041500,
    --       "min": 71538919
    --     },
    --     "lastUpdatedTime": {
    --       "max": 2438620,
    --       "min": 18087967
    --     }
    --   }
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.name', 'et exercitation s'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.unit', 'pariatur esse qui'
    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]', 2274246036570026
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetIds[1]', 8922483798410046
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[0]', 'proident Ut consequat in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetExternalIds[1]', 'elit incididunt aliqua'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[0]', 7714215516056826
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.rootAssetIds[1]', 4275780546438472
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.assetSubtreeIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.assetSubtreeIds[1].externalId', 're'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.dataSetIds[0].id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.dataSetIds[1].externalId', 'exercitation nisi elit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'filter.externalIdPrefix', 'aute Ut nostrud commodo in'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.max', 16041500
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.createdTime.min', 71538919
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.max', 2438620
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'filter.lastUpdatedTime.min', 18087967

    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/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": "et exercitation s",
        "unit": "pariatur esse qui",
        "isString": true,
        "isStep": false,
        "metadata": {},
        "assetIds": [
            2274246036570026,
            8922483798410046
        ],
        "assetExternalIds": [
            "proident Ut consequat in",
            "elit incididunt aliqua"
        ],
        "rootAssetIds": [
            7714215516056826,
            4275780546438472
        ],
        "assetSubtreeIds": [
            {
                "id": 7555548287718054
            },
            {
                "externalId": "re"
            }
        ],
        "dataSetIds": [
            {
                "id": 5946532482497628
            },
            {
                "externalId": "exercitation nisi elit"
            }
        ],
        "externalIdPrefix": "aute Ut nostrud commodo in",
        "createdTime": {
            "max": 16041500,
            "min": 71538919
        },
        "lastUpdatedTime": {
            "max": 2438620,
            "min": 18087967
        }
    }
}'
https://domain.com/api/v1/projects/{{project}}/timeseries/aggregate

Postman Collection Item JSON

{
  "id": "aggregateTimeSeries",
  "name": "Aggregate time series",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "timeseries",
        "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": "Count the number of time series that match the given filter",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"filter\": {\n        \"name\": \"et exercitation s\",\n        \"unit\": \"pariatur esse qui\",\n        \"isString\": true,\n        \"isStep\": false,\n        \"metadata\": {},\n        \"assetIds\": [\n            2274246036570026,\n            8922483798410046\n        ],\n        \"assetExternalIds\": [\n            \"proident Ut consequat in\",\n            \"elit incididunt aliqua\"\n        ],\n        \"rootAssetIds\": [\n            7714215516056826,\n            4275780546438472\n        ],\n        \"assetSubtreeIds\": [\n            {\n                \"id\": 7555548287718054\n            },\n            {\n                \"externalId\": \"re\"\n            }\n        ],\n        \"dataSetIds\": [\n            {\n                \"id\": 5946532482497628\n            },\n            {\n                \"externalId\": \"exercitation nisi elit\"\n            }\n        ],\n        \"externalIdPrefix\": \"aute Ut nostrud commodo in\",\n        \"createdTime\": {\n            \"max\": 16041500,\n            \"min\": 71538919\n        },\n        \"lastUpdatedTime\": {\n            \"max\": 2438620,\n            \"min\": 18087967\n        }\n    }\n}"
    }
  }
}