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
DECLARE @queryParams int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'from', -62147425
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'to', -62147425
EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'query', 'tempor Ut sed velit'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api.app.ddog-gov.com/api/v1/query', @queryParams
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 @queryParams
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "error": "officia dolor dolor enim Ut",
-- "from_date": 74851718,
-- "group_by": [
-- "Ut sint veniam voluptate id",
-- "laborum dolore fugiat quis"
-- ],
-- "message": "commodo Duis dolore",
-- "query": "irure nulla",
-- "res_type": "time_series",
-- "series": [
-- {
-- "aggr": "avg",
-- "display_name": "system.cpu.idle",
-- "end": 40693612,
-- "expression": "system.cpu.idle{host:foo,env:test}",
-- "interval": 40405386,
-- "length": -62156772,
-- "metric": "system.cpu.idle",
-- "pointlist": [
-- [
-- 1681683300000,
-- 77.62145685254418
-- ]
-- ],
-- "query_index": -41586801,
-- "scope": "host:foo,env:test",
-- "start": -45245073,
-- "tag_set": [
-- "aute incididunt enim",
-- "dolore mollit amet esse"
-- ],
-- "unit": [
-- {
-- "family": "time",
-- "name": "minute",
-- "plural": "minutes",
-- "scale_factor": 60,
-- "short_name": "min"
-- },
-- {
-- "family": "time",
-- "name": "minute",
-- "plural": "minutes",
-- "scale_factor": 60,
-- "short_name": "min"
-- }
-- ]
-- },
-- {
-- "aggr": "avg",
-- "display_name": "system.cpu.idle",
-- "end": -49813044,
-- "expression": "system.cpu.idle{host:foo,env:test}",
-- "interval": -86046844,
-- "length": 71311767,
-- "metric": "system.cpu.idle",
-- "pointlist": [
-- [
-- 1681683300000,
-- 77.62145685254418
-- ]
-- ],
-- "query_index": -70553970,
-- "scope": "host:foo,env:test",
-- "start": 3842833,
-- "tag_set": [
-- "sit enim consectetur",
-- "Duis"
-- ],
-- "unit": [
-- {
-- "family": "time",
-- "name": "minute",
-- "plural": "minutes",
-- "scale_factor": 60,
-- "short_name": "min"
-- },
-- {
-- "family": "time",
-- "name": "minute",
-- "plural": "minutes",
-- "scale_factor": 60,
-- "short_name": "min"
-- }
-- ]
-- }
-- ],
-- "status": "ok",
-- "to_date": 39411541
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @strVal nvarchar(4000)
DECLARE @aggr nvarchar(4000)
DECLARE @display_name nvarchar(4000)
DECLARE @v_end int
DECLARE @expression nvarchar(4000)
DECLARE @interval int
DECLARE @length int
DECLARE @metric nvarchar(4000)
DECLARE @query_index int
DECLARE @scope nvarchar(4000)
DECLARE @start int
DECLARE @j int
DECLARE @count_j int
DECLARE @k int
DECLARE @count_k int
DECLARE @intVal int
DECLARE @family nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @plural nvarchar(4000)
DECLARE @scale_factor int
DECLARE @short_name nvarchar(4000)
DECLARE @error nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @error OUT, 'error'
DECLARE @from_date int
EXEC sp_OAMethod @jResp, 'IntOf', @from_date OUT, 'from_date'
DECLARE @message nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @message OUT, 'message'
DECLARE @query nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @query OUT, 'query'
DECLARE @res_type nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @res_type OUT, 'res_type'
DECLARE @status nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
DECLARE @to_date int
EXEC sp_OAMethod @jResp, 'IntOf', @to_date OUT, 'to_date'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'group_by'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'group_by[i]'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'series'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @aggr OUT, 'series[i].aggr'
EXEC sp_OAMethod @jResp, 'StringOf', @display_name OUT, 'series[i].display_name'
EXEC sp_OAMethod @jResp, 'IntOf', @v_end OUT, 'series[i].end'
EXEC sp_OAMethod @jResp, 'StringOf', @expression OUT, 'series[i].expression'
EXEC sp_OAMethod @jResp, 'IntOf', @interval OUT, 'series[i].interval'
EXEC sp_OAMethod @jResp, 'IntOf', @length OUT, 'series[i].length'
EXEC sp_OAMethod @jResp, 'StringOf', @metric OUT, 'series[i].metric'
EXEC sp_OAMethod @jResp, 'IntOf', @query_index OUT, 'series[i].query_index'
EXEC sp_OAMethod @jResp, 'StringOf', @scope OUT, 'series[i].scope'
EXEC sp_OAMethod @jResp, 'IntOf', @start OUT, 'series[i].start'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'series[i].pointlist'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
SELECT @k = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_k OUT, 'series[i].pointlist[j]'
WHILE @k < @count_k
BEGIN
EXEC sp_OASetProperty @jResp, 'K', @k
EXEC sp_OAMethod @jResp, 'IntOf', @intVal OUT, 'series[i].pointlist[j][k]'
SELECT @k = @k + 1
END
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'series[i].tag_set'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'series[i].tag_set[j]'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'series[i].unit'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @family OUT, 'series[i].unit[j].family'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'series[i].unit[j].name'
EXEC sp_OAMethod @jResp, 'StringOf', @plural OUT, 'series[i].unit[j].plural'
EXEC sp_OAMethod @jResp, 'IntOf', @scale_factor OUT, 'series[i].unit[j].scale_factor'
EXEC sp_OAMethod @jResp, 'StringOf', @short_name OUT, 'series[i].unit[j].short_name'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -G -d "from=-62147425"
-d "to=-62147425"
-d "query=tempor%20Ut%20sed%20velit"
-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/query
Postman Collection Item JSON
{
"name": "Query timeseries points",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/query?from=-62147425&to=-62147425&query=tempor Ut sed velit",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"query"
],
"query": [
{
"key": "from",
"value": "-62147425",
"description": "(Required) Start of the queried time period, seconds since the Unix epoch."
},
{
"key": "to",
"value": "-62147425",
"description": "(Required) End of the queried time period, seconds since the Unix epoch."
},
{
"key": "query",
"value": "tempor Ut sed velit",
"description": "(Required) Query string."
}
]
},
"description": "Query timeseries points."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/query?from=-62147425&to=-62147425&query=tempor Ut sed velit",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"query"
],
"query": [
{
"key": "from",
"value": "-62147425",
"description": "(Required) Start of the queried time period, seconds since the Unix epoch."
},
{
"key": "to",
"value": "-62147425",
"description": "(Required) End of the queried time period, seconds since the Unix epoch."
},
{
"key": "query",
"value": "tempor Ut sed velit",
"description": "(Required) Query string."
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"error\": \"officia dolor dolor enim Ut\",\n \"from_date\": 74851718,\n \"group_by\": [\n \"Ut sint veniam voluptate id\",\n \"laborum dolore fugiat quis\"\n ],\n \"message\": \"commodo Duis dolore\",\n \"query\": \"irure nulla\",\n \"res_type\": \"time_series\",\n \"series\": [\n {\n \"aggr\": \"avg\",\n \"display_name\": \"system.cpu.idle\",\n \"end\": 40693612,\n \"expression\": \"system.cpu.idle{host:foo,env:test}\",\n \"interval\": 40405386,\n \"length\": -62156772,\n \"metric\": \"system.cpu.idle\",\n \"pointlist\": [\n [\n 1681683300000,\n 77.62145685254418\n ]\n ],\n \"query_index\": -41586801,\n \"scope\": \"host:foo,env:test\",\n \"start\": -45245073,\n \"tag_set\": [\n \"aute incididunt enim\",\n \"dolore mollit amet esse\"\n ],\n \"unit\": [\n {\n \"family\": \"time\",\n \"name\": \"minute\",\n \"plural\": \"minutes\",\n \"scale_factor\": 60,\n \"short_name\": \"min\"\n },\n {\n \"family\": \"time\",\n \"name\": \"minute\",\n \"plural\": \"minutes\",\n \"scale_factor\": 60,\n \"short_name\": \"min\"\n }\n ]\n },\n {\n \"aggr\": \"avg\",\n \"display_name\": \"system.cpu.idle\",\n \"end\": -49813044,\n \"expression\": \"system.cpu.idle{host:foo,env:test}\",\n \"interval\": -86046844,\n \"length\": 71311767,\n \"metric\": \"system.cpu.idle\",\n \"pointlist\": [\n [\n 1681683300000,\n 77.62145685254418\n ]\n ],\n \"query_index\": -70553970,\n \"scope\": \"host:foo,env:test\",\n \"start\": 3842833,\n \"tag_set\": [\n \"sit enim consectetur\",\n \"Duis\"\n ],\n \"unit\": [\n {\n \"family\": \"time\",\n \"name\": \"minute\",\n \"plural\": \"minutes\",\n \"scale_factor\": 60,\n \"short_name\": \"min\"\n },\n {\n \"family\": \"time\",\n \"name\": \"minute\",\n \"plural\": \"minutes\",\n \"scale_factor\": 60,\n \"short_name\": \"min\"\n }\n ]\n }\n ],\n \"status\": \"ok\",\n \"to_date\": 39411541\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/query?from=-62147425&to=-62147425&query=tempor Ut sed velit",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"query"
],
"query": [
{
"key": "from",
"value": "-62147425",
"description": "(Required) Start of the queried time period, seconds since the Unix epoch."
},
{
"key": "to",
"value": "-62147425",
"description": "(Required) End of the queried time period, seconds since the Unix epoch."
},
{
"key": "query",
"value": "tempor Ut sed velit",
"description": "(Required) Query string."
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/query?from=-62147425&to=-62147425&query=tempor Ut sed velit",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"query"
],
"query": [
{
"key": "from",
"value": "-62147425",
"description": "(Required) Start of the queried time period, seconds since the Unix epoch."
},
{
"key": "to",
"value": "-62147425",
"description": "(Required) End of the queried time period, seconds since the Unix epoch."
},
{
"key": "query",
"value": "tempor Ut sed velit",
"description": "(Required) Query string."
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/query?from=-62147425&to=-62147425&query=tempor Ut sed velit",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"query"
],
"query": [
{
"key": "from",
"value": "-62147425",
"description": "(Required) Start of the queried time period, seconds since the Unix epoch."
},
{
"key": "to",
"value": "-62147425",
"description": "(Required) End of the queried time period, seconds since the Unix epoch."
},
{
"key": "query",
"value": "tempor Ut sed velit",
"description": "(Required) Query string."
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
}
]
}