Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *device;
const wchar_t *duration;
const wchar_t *execution_rule;
const wchar_t *location;
const wchar_t *result_id;
const wchar_t *retries;
const wchar_t *status;
const wchar_t *test_name;
const wchar_t *test_public_id;
const wchar_t *test_type;
const wchar_t *v_Url;
const wchar_t *Name;
const wchar_t *Branch;
const wchar_t *CommitSha;
const wchar_t *Status;
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();
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
sbResponseBody = CkStringBuilderW_Create();
success = CkHttpW_QuickGetSb(http,L"https://api.app.ddog-gov.com/api/v1/synthetics/ci/batch/:batch_id",sbResponseBody);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpW_getLastStatus(http);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpW_lastHeader(http));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "metadata": {
// "ci": {
// "pipeline": {
// "url": "dolor irure amet aliqua"
// },
// "provider": {
// "name": "velit voluptate minim tempor et"
// }
// },
// "git": {
// "branch": "proident pariatur cillum ipsum",
// "commitSha": "no"
// }
// },
// "results": [
// {
// "device": "laptop_large",
// "duration": 77555392.34670219,
// "execution_rule": "blocking",
// "location": "nostrud consectetur proident elit",
// "result_id": "ad in",
// "retries": 27165346.602910966,
// "status": "passed",
// "test_name": "in Excepteur",
// "test_public_id": "aute sint",
// "test_type": "browser"
// },
// {
// "device": "laptop_large",
// "duration": -71572766.6529502,
// "execution_rule": "non_blocking",
// "location": "velit ullamco",
// "result_id": "quis irure officia Lorem enim",
// "retries": 66253781.442619294,
// "status": "passed",
// "test_name": "reprehenderit voluptate incididu",
// "test_public_id": "ipsum Duis",
// "test_type": "api"
// }
// ],
// "status": "passed"
// }
// }
// 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.
v_Url = CkJsonObjectW_stringOf(jResp,L"data.metadata.ci.pipeline.url");
Name = CkJsonObjectW_stringOf(jResp,L"data.metadata.ci.provider.name");
Branch = CkJsonObjectW_stringOf(jResp,L"data.metadata.git.branch");
CommitSha = CkJsonObjectW_stringOf(jResp,L"data.metadata.git.commitSha");
Status = CkJsonObjectW_stringOf(jResp,L"data.status");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.results");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
device = CkJsonObjectW_stringOf(jResp,L"data.results[i].device");
duration = CkJsonObjectW_stringOf(jResp,L"data.results[i].duration");
execution_rule = CkJsonObjectW_stringOf(jResp,L"data.results[i].execution_rule");
location = CkJsonObjectW_stringOf(jResp,L"data.results[i].location");
result_id = CkJsonObjectW_stringOf(jResp,L"data.results[i].result_id");
retries = CkJsonObjectW_stringOf(jResp,L"data.results[i].retries");
status = CkJsonObjectW_stringOf(jResp,L"data.results[i].status");
test_name = CkJsonObjectW_stringOf(jResp,L"data.results[i].test_name");
test_public_id = CkJsonObjectW_stringOf(jResp,L"data.results[i].test_public_id");
test_type = CkJsonObjectW_stringOf(jResp,L"data.results[i].test_type");
i = i + 1;
}
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X GET
-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/synthetics/ci/batch/:batch_id
Postman Collection Item JSON
{
"name": "Get details of batch",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/ci/batch/:batch_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"ci",
"batch",
":batch_id"
],
"variable": [
{
"key": "batch_id",
"value": "tempor Ut sed velit"
}
]
},
"description": "Get a batch's updated details."
},
"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/synthetics/ci/batch/:batch_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"ci",
"batch",
":batch_id"
],
"variable": [
{
"key": "batch_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"metadata\": {\n \"ci\": {\n \"pipeline\": {\n \"url\": \"dolor irure amet aliqua\"\n },\n \"provider\": {\n \"name\": \"velit voluptate minim tempor et\"\n }\n },\n \"git\": {\n \"branch\": \"proident pariatur cillum ipsum\",\n \"commitSha\": \"no\"\n }\n },\n \"results\": [\n {\n \"device\": \"laptop_large\",\n \"duration\": 77555392.34670219,\n \"execution_rule\": \"blocking\",\n \"location\": \"nostrud consectetur proident elit\",\n \"result_id\": \"ad in\",\n \"retries\": 27165346.602910966,\n \"status\": \"passed\",\n \"test_name\": \"in Excepteur\",\n \"test_public_id\": \"aute sint\",\n \"test_type\": \"browser\"\n },\n {\n \"device\": \"laptop_large\",\n \"duration\": -71572766.6529502,\n \"execution_rule\": \"non_blocking\",\n \"location\": \"velit ullamco\",\n \"result_id\": \"quis irure officia Lorem enim\",\n \"retries\": 66253781.442619294,\n \"status\": \"passed\",\n \"test_name\": \"reprehenderit voluptate incididu\",\n \"test_public_id\": \"ipsum Duis\",\n \"test_type\": \"api\"\n }\n ],\n \"status\": \"passed\"\n }\n}"
},
{
"name": "Batch does not exist.",
"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/synthetics/ci/batch/:batch_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"ci",
"batch",
":batch_id"
],
"variable": [
{
"key": "batch_id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_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/synthetics/ci/batch/:batch_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"ci",
"batch",
":batch_id"
],
"variable": [
{
"key": "batch_id"
}
]
}
},
"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}"
}
]
}