Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
$oQueryParams = ObjCreate("Chilkat.JsonObject")
$oQueryParams.UpdateInt("from",-62147425)
$oQueryParams.UpdateInt("to",-62147425)
$oQueryParams.UpdateString("query","tempor Ut sed velit")
$oHttp.SetRequestHeader "Accept","application/json"
Local $oResp = $oHttp.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/query",$oQueryParams)
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; 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
Local $strVal
Local $sAggr
Local $sDisplay_name
Local $iV_end
Local $sExpression
Local $interval
Local $iLength
Local $sMetric
Local $iQuery_index
Local $scope
Local $iStart
Local $iJ
Local $iCount_j
Local $iK
Local $iCount_k
Local $intVal
Local $sFamily
Local $sName
Local $sPlural
Local $iScale_factor
Local $short_name
Local $sError = $oJResp.StringOf("error")
Local $iFrom_date = $oJResp.IntOf("from_date")
Local $sMessage = $oJResp.StringOf("message")
Local $sQuery = $oJResp.StringOf("query")
Local $sRes_type = $oJResp.StringOf("res_type")
Local $status = $oJResp.StringOf("status")
Local $iTo_date = $oJResp.IntOf("to_date")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("group_by")
While $i < $iCount_i
$oJResp.I = $i
$strVal = $oJResp.StringOf("group_by[i]")
$i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("series")
While $i < $iCount_i
$oJResp.I = $i
$sAggr = $oJResp.StringOf("series[i].aggr")
$sDisplay_name = $oJResp.StringOf("series[i].display_name")
$iV_end = $oJResp.IntOf("series[i].end")
$sExpression = $oJResp.StringOf("series[i].expression")
$interval = $oJResp.IntOf("series[i].interval")
$iLength = $oJResp.IntOf("series[i].length")
$sMetric = $oJResp.StringOf("series[i].metric")
$iQuery_index = $oJResp.IntOf("series[i].query_index")
$scope = $oJResp.StringOf("series[i].scope")
$iStart = $oJResp.IntOf("series[i].start")
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("series[i].pointlist")
While $iJ < $iCount_j
$oJResp.J = $iJ
$iK = 0
$iCount_k = $oJResp.SizeOfArray("series[i].pointlist[j]")
While $iK < $iCount_k
$oJResp.K = $iK
$intVal = $oJResp.IntOf("series[i].pointlist[j][k]")
$iK = $iK + 1
Wend
$iJ = $iJ + 1
Wend
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("series[i].tag_set")
While $iJ < $iCount_j
$oJResp.J = $iJ
$strVal = $oJResp.StringOf("series[i].tag_set[j]")
$iJ = $iJ + 1
Wend
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("series[i].unit")
While $iJ < $iCount_j
$oJResp.J = $iJ
$sFamily = $oJResp.StringOf("series[i].unit[j].family")
$sName = $oJResp.StringOf("series[i].unit[j].name")
$sPlural = $oJResp.StringOf("series[i].unit[j].plural")
$iScale_factor = $oJResp.IntOf("series[i].unit[j].scale_factor")
$short_name = $oJResp.StringOf("series[i].unit[j].short_name")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend
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}"
}
]
}