Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW queryParams;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *strVal;
const wchar_t *aggr;
const wchar_t *display_name;
int v_end;
const wchar_t *expression;
int interval;
int length;
const wchar_t *metric;
int query_index;
const wchar_t *scope;
int start;
int j;
int count_j;
int k;
int count_k;
int intVal;
const wchar_t *family;
const wchar_t *name;
const wchar_t *plural;
int scale_factor;
const wchar_t *short_name;
const wchar_t *error;
int from_date;
const wchar_t *message;
const wchar_t *query;
const wchar_t *res_type;
const wchar_t *status;
int to_date;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
queryParams = CkJsonObjectW_Create();
CkJsonObjectW_UpdateInt(queryParams,L"from",-62147425);
CkJsonObjectW_UpdateInt(queryParams,L"to",-62147425);
CkJsonObjectW_UpdateString(queryParams,L"query",L"tempor Ut sed velit");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api.app.ddog-gov.com/api/v1/query",queryParams);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
error = CkJsonObjectW_stringOf(jResp,L"error");
from_date = CkJsonObjectW_IntOf(jResp,L"from_date");
message = CkJsonObjectW_stringOf(jResp,L"message");
query = CkJsonObjectW_stringOf(jResp,L"query");
res_type = CkJsonObjectW_stringOf(jResp,L"res_type");
status = CkJsonObjectW_stringOf(jResp,L"status");
to_date = CkJsonObjectW_IntOf(jResp,L"to_date");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"group_by");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"group_by[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"series");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
aggr = CkJsonObjectW_stringOf(jResp,L"series[i].aggr");
display_name = CkJsonObjectW_stringOf(jResp,L"series[i].display_name");
v_end = CkJsonObjectW_IntOf(jResp,L"series[i].end");
expression = CkJsonObjectW_stringOf(jResp,L"series[i].expression");
interval = CkJsonObjectW_IntOf(jResp,L"series[i].interval");
length = CkJsonObjectW_IntOf(jResp,L"series[i].length");
metric = CkJsonObjectW_stringOf(jResp,L"series[i].metric");
query_index = CkJsonObjectW_IntOf(jResp,L"series[i].query_index");
scope = CkJsonObjectW_stringOf(jResp,L"series[i].scope");
start = CkJsonObjectW_IntOf(jResp,L"series[i].start");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"series[i].pointlist");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
k = 0;
count_k = CkJsonObjectW_SizeOfArray(jResp,L"series[i].pointlist[j]");
while (k < count_k) {
CkJsonObjectW_putK(jResp,k);
intVal = CkJsonObjectW_IntOf(jResp,L"series[i].pointlist[j][k]");
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"series[i].tag_set");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"series[i].tag_set[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"series[i].unit");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
family = CkJsonObjectW_stringOf(jResp,L"series[i].unit[j].family");
name = CkJsonObjectW_stringOf(jResp,L"series[i].unit[j].name");
plural = CkJsonObjectW_stringOf(jResp,L"series[i].unit[j].plural");
scale_factor = CkJsonObjectW_IntOf(jResp,L"series[i].unit[j].scale_factor");
short_name = CkJsonObjectW_stringOf(jResp,L"series[i].unit[j].short_name");
j = j + 1;
}
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(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}"
}
]
}