Chilkat Online Tools

Foxpro / Datadog API Collection / Query timeseries points

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loQueryParams
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcStrVal
LOCAL lcAggr
LOCAL lcDisplay_name
LOCAL lnV_end
LOCAL lcExpression
LOCAL lnInterval
LOCAL lnLength
LOCAL lcMetric
LOCAL lnQuery_index
LOCAL lcScope
LOCAL lnStart
LOCAL j
LOCAL lnCount_j
LOCAL k
LOCAL lnCount_k
LOCAL lnIntVal
LOCAL lcFamily
LOCAL lcName
LOCAL lcPlural
LOCAL lnScale_factor
LOCAL lcShort_name
LOCAL lcError
LOCAL lnFrom_date
LOCAL lcMessage
LOCAL lcQuery
LOCAL lcRes_type
LOCAL lcStatus
LOCAL lnTo_date
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')

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loQueryParams = CreateObject('Chilkat.JsonObject')
loQueryParams.UpdateInt("from",-62147425)
loQueryParams.UpdateInt("to",-62147425)
loQueryParams.UpdateString("query","tempor Ut sed velit")

loHttp.SetRequestHeader("Accept","application/json")

loResp = loHttp.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/query",loQueryParams)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loQueryParams
    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 loQueryParams
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

* 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

lcError = loJResp.StringOf("error")
lnFrom_date = loJResp.IntOf("from_date")
lcMessage = loJResp.StringOf("message")
lcQuery = loJResp.StringOf("query")
lcRes_type = loJResp.StringOf("res_type")
lcStatus = loJResp.StringOf("status")
lnTo_date = loJResp.IntOf("to_date")
i = 0
lnCount_i = loJResp.SizeOfArray("group_by")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("group_by[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("series")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcAggr = loJResp.StringOf("series[i].aggr")
    lcDisplay_name = loJResp.StringOf("series[i].display_name")
    lnV_end = loJResp.IntOf("series[i].end")
    lcExpression = loJResp.StringOf("series[i].expression")
    lnInterval = loJResp.IntOf("series[i].interval")
    lnLength = loJResp.IntOf("series[i].length")
    lcMetric = loJResp.StringOf("series[i].metric")
    lnQuery_index = loJResp.IntOf("series[i].query_index")
    lcScope = loJResp.StringOf("series[i].scope")
    lnStart = loJResp.IntOf("series[i].start")
    j = 0
    lnCount_j = loJResp.SizeOfArray("series[i].pointlist")
    DO WHILE j < lnCount_j
        loJResp.J = j
        k = 0
        lnCount_k = loJResp.SizeOfArray("series[i].pointlist[j]")
        DO WHILE k < lnCount_k
            loJResp.K = k
            lnIntVal = loJResp.IntOf("series[i].pointlist[j][k]")
            k = k + 1
        ENDDO
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("series[i].tag_set")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("series[i].tag_set[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJResp.SizeOfArray("series[i].unit")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcFamily = loJResp.StringOf("series[i].unit[j].family")
        lcName = loJResp.StringOf("series[i].unit[j].name")
        lcPlural = loJResp.StringOf("series[i].unit[j].plural")
        lnScale_factor = loJResp.IntOf("series[i].unit[j].scale_factor")
        lcShort_name = loJResp.StringOf("series[i].unit[j].short_name")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loQueryParams
RELEASE loSbResponseBody
RELEASE loJResp

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}"
    }
  ]
}