Foxpro / Datadog API Collection / Query timeseries data across multiple products
Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcQuery_index
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal
LOCAL lcFamily
LOCAL lcName
LOCAL lcPlural
LOCAL lcScale_factor
LOCAL lcShort_name
LOCAL lcV_Type
LOCAL lcErrors
LOCAL i
LOCAL lnCount_i
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
* 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>"
* }
* }
* }
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("data.type","timeseries_request")
loJson.UpdateString("data.attributes.to","<long>")
loJson.UpdateString("data.attributes.from","<long>")
loJson.UpdateString("data.attributes.queries[0].data_source","metrics")
loJson.UpdateString("data.attributes.queries[0].query","<string>")
loJson.UpdateString("data.attributes.queries[0].name","<string>")
loJson.UpdateString("data.attributes.queries[1].data_source","metrics")
loJson.UpdateString("data.attributes.queries[1].query","<string>")
loJson.UpdateString("data.attributes.queries[1].name","<string>")
loJson.UpdateString("data.attributes.formulas[0].formula","<string>")
loJson.UpdateString("data.attributes.formulas[0].limit.count","<integer>")
loJson.UpdateString("data.attributes.formulas[0].limit.order","desc")
loJson.UpdateString("data.attributes.formulas[1].formula","<string>")
loJson.UpdateString("data.attributes.formulas[1].limit.count","<integer>")
loJson.UpdateString("data.attributes.formulas[1].limit.order","desc")
loJson.UpdateString("data.attributes.interval","<long>")
loHttp.SetRequestHeader("Content-Type","application/json")
loHttp.SetRequestHeader("Accept","application/json")
loResp = loHttp.PostJson3("https://api.app.ddog-gov.com/api/v2/query/timeseries","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
CANCEL
ENDIF
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loResp
RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
RELEASE loResp
* 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
lcV_Type = loJResp.StringOf("data.type")
lcErrors = loJResp.StringOf("errors")
i = 0
lnCount_i = loJResp.SizeOfArray("data.attributes.series")
DO WHILE i < lnCount_i
loJResp.I = i
lcQuery_index = loJResp.StringOf("data.attributes.series[i].query_index")
j = 0
lnCount_j = loJResp.SizeOfArray("data.attributes.series[i].group_tags")
DO WHILE j < lnCount_j
loJResp.J = j
lcStrVal = loJResp.StringOf("data.attributes.series[i].group_tags[j]")
j = j + 1
ENDDO
j = 0
lnCount_j = loJResp.SizeOfArray("data.attributes.series[i].unit")
DO WHILE j < lnCount_j
loJResp.J = j
lcFamily = loJResp.StringOf("data.attributes.series[i].unit[j].family")
lcName = loJResp.StringOf("data.attributes.series[i].unit[j].name")
lcPlural = loJResp.StringOf("data.attributes.series[i].unit[j].plural")
lcScale_factor = loJResp.StringOf("data.attributes.series[i].unit[j].scale_factor")
lcShort_name = loJResp.StringOf("data.attributes.series[i].unit[j].short_name")
j = j + 1
ENDDO
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("data.attributes.times")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("data.attributes.times[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("data.attributes.values")
DO WHILE i < lnCount_i
loJResp.I = i
j = 0
lnCount_j = loJResp.SizeOfArray("data.attributes.values[i]")
DO WHILE j < lnCount_j
loJResp.J = j
lcStrVal = loJResp.StringOf("data.attributes.values[i][j]")
j = j + 1
ENDDO
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp
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}"
}
]
}