autoit / Datadog API Collection / Query timeseries data across multiple products
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
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "data": {
; "type": "timeseries_request",
; "attributes": {
; "to": "<long>",
; "from": "<long>",
; "queries": [
; {
; "data_source": "metrics",
; "query": "<string>",
; "name": "<string>"
; },
; {
; "data_source": "metrics",
; "query": "<string>",
; "name": "<string>"
; }
; ],
; "formulas": [
; {
; "formula": "<string>",
; "limit": {
; "count": "<integer>",
; "order": "desc"
; }
; },
; {
; "formula": "<string>",
; "limit": {
; "count": "<integer>",
; "order": "desc"
; }
; }
; ],
; "interval": "<long>"
; }
; }
; }
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("data.type","timeseries_request")
$oJson.UpdateString("data.attributes.to","<long>")
$oJson.UpdateString("data.attributes.from","<long>")
$oJson.UpdateString("data.attributes.queries[0].data_source","metrics")
$oJson.UpdateString("data.attributes.queries[0].query","<string>")
$oJson.UpdateString("data.attributes.queries[0].name","<string>")
$oJson.UpdateString("data.attributes.queries[1].data_source","metrics")
$oJson.UpdateString("data.attributes.queries[1].query","<string>")
$oJson.UpdateString("data.attributes.queries[1].name","<string>")
$oJson.UpdateString("data.attributes.formulas[0].formula","<string>")
$oJson.UpdateString("data.attributes.formulas[0].limit.count","<integer>")
$oJson.UpdateString("data.attributes.formulas[0].limit.order","desc")
$oJson.UpdateString("data.attributes.formulas[1].formula","<string>")
$oJson.UpdateString("data.attributes.formulas[1].limit.count","<integer>")
$oJson.UpdateString("data.attributes.formulas[1].limit.order","desc")
$oJson.UpdateString("data.attributes.interval","<long>")
$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Accept","application/json"
Local $oResp = $oHttp.PostJson3("https://api.app.ddog-gov.com/api/v2/query/timeseries","application/json",$oJson)
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)
; {
; "data": {
; "attributes": {
; "series": [
; {
; "group_tags": [
; "<string>",
; "<string>"
; ],
; "query_index": "<integer>",
; "unit": [
; {
; "family": "<string>",
; "name": "<string>",
; "plural": "<string>",
; "scale_factor": "<double>",
; "short_name": "<string>"
; },
; {
; "family": "<string>",
; "name": "<string>",
; "plural": "<string>",
; "scale_factor": "<double>",
; "short_name": "<string>"
; }
; ]
; },
; {
; "group_tags": [
; "<string>",
; "<string>"
; ],
; "query_index": "<integer>",
; "unit": [
; {
; "family": "<string>",
; "name": "<string>",
; "plural": "<string>",
; "scale_factor": "<double>",
; "short_name": "<string>"
; },
; {
; "family": "<string>",
; "name": "<string>",
; "plural": "<string>",
; "scale_factor": "<double>",
; "short_name": "<string>"
; }
; ]
; }
; ],
; "times": [
; "<long>",
; "<long>"
; ],
; "values": [
; [
; "<double>",
; "<double>"
; ],
; [
; "<double>",
; "<double>"
; ]
; ]
; },
; "type": "timeseries_response"
; },
; "errors": "<string>"
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Local $sQuery_index
Local $iJ
Local $iCount_j
Local $strVal
Local $sFamily
Local $sName
Local $sPlural
Local $scale_factor
Local $short_name
Local $sV_Type = $oJResp.StringOf("data.type")
Local $sErrors = $oJResp.StringOf("errors")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data.attributes.series")
While $i < $iCount_i
$oJResp.I = $i
$sQuery_index = $oJResp.StringOf("data.attributes.series[i].query_index")
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("data.attributes.series[i].group_tags")
While $iJ < $iCount_j
$oJResp.J = $iJ
$strVal = $oJResp.StringOf("data.attributes.series[i].group_tags[j]")
$iJ = $iJ + 1
Wend
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("data.attributes.series[i].unit")
While $iJ < $iCount_j
$oJResp.J = $iJ
$sFamily = $oJResp.StringOf("data.attributes.series[i].unit[j].family")
$sName = $oJResp.StringOf("data.attributes.series[i].unit[j].name")
$sPlural = $oJResp.StringOf("data.attributes.series[i].unit[j].plural")
$scale_factor = $oJResp.StringOf("data.attributes.series[i].unit[j].scale_factor")
$short_name = $oJResp.StringOf("data.attributes.series[i].unit[j].short_name")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("data.attributes.times")
While $i < $iCount_i
$oJResp.I = $i
$strVal = $oJResp.StringOf("data.attributes.times[i]")
$i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("data.attributes.values")
While $i < $iCount_i
$oJResp.I = $i
$iJ = 0
$iCount_j = $oJResp.SizeOfArray("data.attributes.values[i]")
While $iJ < $iCount_j
$oJResp.J = $iJ
$strVal = $oJResp.StringOf("data.attributes.values[i][j]")
$iJ = $iJ + 1
Wend
$i = $i + 1
Wend
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"type": "timeseries_request",
"attributes": {
"to": "<long>",
"from": "<long>",
"queries": [
{
"data_source": "metrics",
"query": "<string>",
"name": "<string>"
},
{
"data_source": "metrics",
"query": "<string>",
"name": "<string>"
}
],
"formulas": [
{
"formula": "<string>",
"limit": {
"count": "<integer>",
"order": "desc"
}
},
{
"formula": "<string>",
"limit": {
"count": "<integer>",
"order": "desc"
}
}
],
"interval": "<long>"
}
}
}'
https://api.app.ddog-gov.com/api/v2/query/timeseries
Postman Collection Item JSON
{
"name": "Query timeseries data across multiple products",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
},
"description": "Query timeseries data across various data sources and\nprocess the data by applying formulas and functions."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"attributes\": {\n \"series\": [\n {\n \"group_tags\": [\n \"<string>\",\n \"<string>\"\n ],\n \"query_index\": \"<integer>\",\n \"unit\": [\n {\n \"family\": \"<string>\",\n \"name\": \"<string>\",\n \"plural\": \"<string>\",\n \"scale_factor\": \"<double>\",\n \"short_name\": \"<string>\"\n },\n {\n \"family\": \"<string>\",\n \"name\": \"<string>\",\n \"plural\": \"<string>\",\n \"scale_factor\": \"<double>\",\n \"short_name\": \"<string>\"\n }\n ]\n },\n {\n \"group_tags\": [\n \"<string>\",\n \"<string>\"\n ],\n \"query_index\": \"<integer>\",\n \"unit\": [\n {\n \"family\": \"<string>\",\n \"name\": \"<string>\",\n \"plural\": \"<string>\",\n \"scale_factor\": \"<double>\",\n \"short_name\": \"<string>\"\n },\n {\n \"family\": \"<string>\",\n \"name\": \"<string>\",\n \"plural\": \"<string>\",\n \"scale_factor\": \"<double>\",\n \"short_name\": \"<string>\"\n }\n ]\n }\n ],\n \"times\": [\n \"<long>\",\n \"<long>\"\n ],\n \"values\": [\n [\n \"<double>\",\n \"<double>\"\n ],\n [\n \"<double>\",\n \"<double>\"\n ]\n ]\n },\n \"type\": \"timeseries_response\"\n },\n \"errors\": \"<string>\"\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Unauthorized",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"timeseries_request\",\n \"attributes\": {\n \"to\": \"<long>\",\n \"from\": \"<long>\",\n \"queries\": [\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"data_source\": \"metrics\",\n \"query\": \"<string>\",\n \"name\": \"<string>\"\n }\n ],\n \"formulas\": [\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n },\n {\n \"formula\": \"<string>\",\n \"limit\": {\n \"count\": \"<integer>\",\n \"order\": \"desc\"\n }\n }\n ],\n \"interval\": \"<long>\"\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/query/timeseries",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"query",
"timeseries"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
}
]
}