Chilkat Online Tools

PowerBuilder / Datadog API Collection / Query timeseries points

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_StrVal
string ls_Aggr
string ls_Display_name
integer li_V_end
string ls_Expression
integer li_Interval
integer li_Length
string ls_Metric
integer li_Query_index
string ls_Scope
integer li_Start
integer j
integer li_Count_j
integer k
integer li_Count_k
integer li_IntVal
string ls_Family
string ls_Name
string ls_Plural
integer li_Scale_factor
string ls_Short_name
string ls_Error
integer li_From_date
string ls_Message
string ls_Query
string ls_Res_type
string ls_Status
integer li_To_date
integer i
integer li_Count_i

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_QueryParams = create oleobject
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_QueryParams.UpdateInt("from",-62147425)
loo_QueryParams.UpdateInt("to",-62147425)
loo_QueryParams.UpdateString("query","tempor Ut sed velit")

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

loo_Resp = loo_Http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/query",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_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

ls_Error = loo_JResp.StringOf("error")
li_From_date = loo_JResp.IntOf("from_date")
ls_Message = loo_JResp.StringOf("message")
ls_Query = loo_JResp.StringOf("query")
ls_Res_type = loo_JResp.StringOf("res_type")
ls_Status = loo_JResp.StringOf("status")
li_To_date = loo_JResp.IntOf("to_date")
i = 0
li_Count_i = loo_JResp.SizeOfArray("group_by")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("group_by[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("series")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Aggr = loo_JResp.StringOf("series[i].aggr")
    ls_Display_name = loo_JResp.StringOf("series[i].display_name")
    li_V_end = loo_JResp.IntOf("series[i].end")
    ls_Expression = loo_JResp.StringOf("series[i].expression")
    li_Interval = loo_JResp.IntOf("series[i].interval")
    li_Length = loo_JResp.IntOf("series[i].length")
    ls_Metric = loo_JResp.StringOf("series[i].metric")
    li_Query_index = loo_JResp.IntOf("series[i].query_index")
    ls_Scope = loo_JResp.StringOf("series[i].scope")
    li_Start = loo_JResp.IntOf("series[i].start")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("series[i].pointlist")
    do while j < li_Count_j
        loo_JResp.J = j
        k = 0
        li_Count_k = loo_JResp.SizeOfArray("series[i].pointlist[j]")
        do while k < li_Count_k
            loo_JResp.K = k
            li_IntVal = loo_JResp.IntOf("series[i].pointlist[j][k]")
            k = k + 1
        loop
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("series[i].tag_set")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("series[i].tag_set[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("series[i].unit")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Family = loo_JResp.StringOf("series[i].unit[j].family")
        ls_Name = loo_JResp.StringOf("series[i].unit[j].name")
        ls_Plural = loo_JResp.StringOf("series[i].unit[j].plural")
        li_Scale_factor = loo_JResp.IntOf("series[i].unit[j].scale_factor")
        ls_Short_name = loo_JResp.StringOf("series[i].unit[j].short_name")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

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