Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vQueryParams
Handle hoQueryParams
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sStrVal
String sAggr
String sDisplay_name
Integer iV_end
String sExpression
Integer iInterval
Integer iLength
String sMetric
Integer iQuery_index
String sScope
Integer iStart
Integer j
Integer iCount_j
Integer k
Integer iCount_k
Integer iIntVal
String sFamily
String sName
String sPlural
Integer iScale_factor
String sShort_name
String sError
Integer iFrom_date
String sMessage
String sQuery
String sRes_type
String sStatus
Integer iTo_date
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
If (Not(IsComObjectCreated(hoQueryParams))) Begin
Send CreateComObject of hoQueryParams
End
Get ComUpdateInt Of hoQueryParams "from" -62147425 To iSuccess
Get ComUpdateInt Of hoQueryParams "to" -62147425 To iSuccess
Get ComUpdateString Of hoQueryParams "query" "tempor Ut sed velit" To iSuccess
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Get pvComObject of hoQueryParams to vQueryParams
Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/query" vQueryParams To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// 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
Get ComStringOf Of hoJResp "error" To sError
Get ComIntOf Of hoJResp "from_date" To iFrom_date
Get ComStringOf Of hoJResp "message" To sMessage
Get ComStringOf Of hoJResp "query" To sQuery
Get ComStringOf Of hoJResp "res_type" To sRes_type
Get ComStringOf Of hoJResp "status" To sStatus
Get ComIntOf Of hoJResp "to_date" To iTo_date
Move 0 To i
Get ComSizeOfArray Of hoJResp "group_by" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "group_by[i]" To sStrVal
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "series" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "series[i].aggr" To sAggr
Get ComStringOf Of hoJResp "series[i].display_name" To sDisplay_name
Get ComIntOf Of hoJResp "series[i].end" To iV_end
Get ComStringOf Of hoJResp "series[i].expression" To sExpression
Get ComIntOf Of hoJResp "series[i].interval" To iInterval
Get ComIntOf Of hoJResp "series[i].length" To iLength
Get ComStringOf Of hoJResp "series[i].metric" To sMetric
Get ComIntOf Of hoJResp "series[i].query_index" To iQuery_index
Get ComStringOf Of hoJResp "series[i].scope" To sScope
Get ComIntOf Of hoJResp "series[i].start" To iStart
Move 0 To j
Get ComSizeOfArray Of hoJResp "series[i].pointlist" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Move 0 To k
Get ComSizeOfArray Of hoJResp "series[i].pointlist[j]" To iCount_k
While (k < iCount_k)
Set ComK Of hoJResp To k
Get ComIntOf Of hoJResp "series[i].pointlist[j][k]" To iIntVal
Move (k + 1) To k
Loop
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "series[i].tag_set" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "series[i].tag_set[j]" To sStrVal
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "series[i].unit" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "series[i].unit[j].family" To sFamily
Get ComStringOf Of hoJResp "series[i].unit[j].name" To sName
Get ComStringOf Of hoJResp "series[i].unit[j].plural" To sPlural
Get ComIntOf Of hoJResp "series[i].unit[j].scale_factor" To iScale_factor
Get ComStringOf Of hoJResp "series[i].unit[j].short_name" To sShort_name
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
End_Procedure
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}"
}
]
}