SQL Server / Cognite API v1 / Retrieve data points
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.
-- {
-- "items": [
-- {
-- "externalId": "ut culpa Excepteur",
-- "start": 0,
-- "end": -12222847,
-- "limit": 43358925,
-- "aggregates": [
-- "interpolation",
-- "max"
-- ],
-- "granularity": "a",
-- "includeOutsidePoints": false
-- },
-- {
-- "externalId": "aliquip",
-- "start": 0,
-- "end": -6309638,
-- "limit": 57543521,
-- "aggregates": [
-- "max",
-- "min"
-- ],
-- "granularity": "",
-- "includeOutsidePoints": false
-- }
-- ],
-- "start": "velit",
-- "end": 50328109,
-- "limit": 100,
-- "aggregates": [
-- "count",
-- "max"
-- ],
-- "granularity": "mollit dolore",
-- "includeOutsidePoints": false,
-- "ignoreUnknownIds": false
-- }
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, 'items[0].externalId', 'ut culpa Excepteur'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].start', 0
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].end', -12222847
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].limit', 43358925
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].aggregates[0]', 'interpolation'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].aggregates[1]', 'max'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].granularity', 'a'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].includeOutsidePoints', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].externalId', 'aliquip'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].start', 0
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].end', -6309638
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].limit', 57543521
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].aggregates[0]', 'max'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].aggregates[1]', 'min'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].granularity', ''
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].includeOutsidePoints', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'start', 'velit'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'end', 50328109
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'limit', 100
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'aggregates[0]', 'count'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'aggregates[1]', 'max'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'granularity', 'mollit dolore'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'includeOutsidePoints', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ignoreUnknownIds', 0
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/data/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 '{
"items": [
{
"externalId": "ut culpa Excepteur",
"start": 0,
"end": -12222847,
"limit": 43358925,
"aggregates": [
"interpolation",
"max"
],
"granularity": "a",
"includeOutsidePoints": false
},
{
"externalId": "aliquip",
"start": 0,
"end": -6309638,
"limit": 57543521,
"aggregates": [
"max",
"min"
],
"granularity": "",
"includeOutsidePoints": false
}
],
"start": "velit",
"end": 50328109,
"limit": 100,
"aggregates": [
"count",
"max"
],
"granularity": "mollit dolore",
"includeOutsidePoints": false,
"ignoreUnknownIds": false
}'
https://domain.com/api/v1/projects/{{project}}/timeseries/data/list
Postman Collection Item JSON
{
"id": "getMultiTimeSeriesDatapoints",
"name": "Retrieve data points",
"request": {
"url": {
"host": "{{baseUrl}}",
"path": [
"api",
"v1",
"projects",
"{{project}}",
"timeseries",
"data",
"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 data points from multiple time series in a project. This operation supports aggregation, but not pagination. A detailed description of how aggregates work can be found at [our concept guide for aggregation](<https://docs.cognite.com/dev/concepts/aggregation/>).",
"body": {
"mode": "raw",
"raw": "{\n \"items\": [\n {\n \"externalId\": \"ut culpa Excepteur\",\n \"start\": 0,\n \"end\": -12222847,\n \"limit\": 43358925,\n \"aggregates\": [\n \"interpolation\",\n \"max\"\n ],\n \"granularity\": \"a\",\n \"includeOutsidePoints\": false\n },\n {\n \"externalId\": \"aliquip\",\n \"start\": 0,\n \"end\": -6309638,\n \"limit\": 57543521,\n \"aggregates\": [\n \"max\",\n \"min\"\n ],\n \"granularity\": \"\",\n \"includeOutsidePoints\": false\n }\n ],\n \"start\": \"velit\",\n \"end\": 50328109,\n \"limit\": 100,\n \"aggregates\": [\n \"count\",\n \"max\"\n ],\n \"granularity\": \"mollit dolore\",\n \"includeOutsidePoints\": false,\n \"ignoreUnknownIds\": false\n}"
}
}
}