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;
int intVal;
const wchar_t *strVal;
int target;
const wchar_t *timeframe;
int warning;
int Created_at;
const wchar_t *v_Email;
const wchar_t *Handle;
const wchar_t *Name;
const wchar_t *Description;
const wchar_t *Id;
int Modified_at;
const wchar_t *dataName;
const wchar_t *Numerator;
const wchar_t *Denominator;
const wchar_t *Target_threshold;
const wchar_t *Timeframe;
const wchar_t *v_Type;
const wchar_t *Warning_threshold;
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_UpdateString(queryParams,L"with_configured_alert_ids",L"true");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api.app.ddog-gov.com/api/v1/slo/:slo_id",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)
// {
// "data": {
// "configured_alert_ids": [
// 123,
// 456,
// 789
// ],
// "created_at": 17466638,
// "creator": {
// "email": "proident ex ullamco",
// "handle": "laborum ad ex non",
// "name": "officia dolor consectetur nisi"
// },
// "description": "est id",
// "groups": [
// "env:prod",
// "role:mysql"
// ],
// "id": "esse cillum anim ",
// "modified_at": -26273532,
// "monitor_ids": [
// -91642399,
// 93741
// ],
// "monitor_tags": [
// "aliquip nulla Lorem ut",
// "reprehenderit velit"
// ],
// "name": "Custom Metric SLO",
// "query": {
// "numerator": "sum:my.custom.metric{type:good}.as_count()",
// "denominator": "sum:my.custom.metric{*}.as_count()"
// },
// "tags": [
// "env:prod",
// "app:core"
// ],
// "target_threshold": 99.9,
// "thresholds": [
// {
// "target": 95,
// "timeframe": "7d"
// },
// {
// "target": 95,
// "timeframe": "30d",
// "warning": 97
// }
// ],
// "timeframe": "30d",
// "type": "metric",
// "warning_threshold": 99.95
// },
// "errors": [
// "consectetur velit",
// "elit in"
// ]
// }
// 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.
Created_at = CkJsonObjectW_IntOf(jResp,L"data.created_at");
v_Email = CkJsonObjectW_stringOf(jResp,L"data.creator.email");
Handle = CkJsonObjectW_stringOf(jResp,L"data.creator.handle");
Name = CkJsonObjectW_stringOf(jResp,L"data.creator.name");
Description = CkJsonObjectW_stringOf(jResp,L"data.description");
Id = CkJsonObjectW_stringOf(jResp,L"data.id");
Modified_at = CkJsonObjectW_IntOf(jResp,L"data.modified_at");
dataName = CkJsonObjectW_stringOf(jResp,L"data.name");
Numerator = CkJsonObjectW_stringOf(jResp,L"data.query.numerator");
Denominator = CkJsonObjectW_stringOf(jResp,L"data.query.denominator");
Target_threshold = CkJsonObjectW_stringOf(jResp,L"data.target_threshold");
Timeframe = CkJsonObjectW_stringOf(jResp,L"data.timeframe");
v_Type = CkJsonObjectW_stringOf(jResp,L"data.type");
Warning_threshold = CkJsonObjectW_stringOf(jResp,L"data.warning_threshold");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.configured_alert_ids");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
intVal = CkJsonObjectW_IntOf(jResp,L"data.configured_alert_ids[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.groups");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"data.groups[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.monitor_ids");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
intVal = CkJsonObjectW_IntOf(jResp,L"data.monitor_ids[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.monitor_tags");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"data.monitor_tags[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.tags");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"data.tags[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.thresholds");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
target = CkJsonObjectW_IntOf(jResp,L"data.thresholds[i].target");
timeframe = CkJsonObjectW_stringOf(jResp,L"data.thresholds[i].timeframe");
warning = CkJsonObjectW_IntOf(jResp,L"data.thresholds[i].warning");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"errors");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"errors[i]");
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(queryParams);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -G -d "with_configured_alert_ids=true"
-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/slo/:slo_id
Postman Collection Item JSON
{
"name": "Get an SLO's details",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
":slo_id"
],
"query": [
{
"key": "with_configured_alert_ids",
"value": "true",
"description": "Get the IDs of SLO monitors that reference this SLO."
}
],
"variable": [
{
"key": "slo_id",
"value": "tempor Ut sed velit"
}
]
},
"description": "Get a service level objective object."
},
"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/slo/:slo_id?with_configured_alert_ids=true",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
":slo_id"
],
"query": [
{
"key": "with_configured_alert_ids",
"value": "true",
"description": "Get the IDs of SLO monitors that reference this SLO."
}
],
"variable": [
{
"key": "slo_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"configured_alert_ids\": [\n 123,\n 456,\n 789\n ],\n \"created_at\": 17466638,\n \"creator\": {\n \"email\": \"proident ex ullamco\",\n \"handle\": \"laborum ad ex non\",\n \"name\": \"officia dolor consectetur nisi\"\n },\n \"description\": \"est id\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"id\": \"esse cillum anim \",\n \"modified_at\": -26273532,\n \"monitor_ids\": [\n -91642399,\n 93741\n ],\n \"monitor_tags\": [\n \"aliquip nulla Lorem ut\",\n \"reprehenderit velit\"\n ],\n \"name\": \"Custom Metric SLO\",\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"timeframe\": \"30d\",\n \"type\": \"metric\",\n \"warning_threshold\": 99.95\n },\n \"errors\": [\n \"consectetur velit\",\n \"elit in\"\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/slo/:slo_id?with_configured_alert_ids=true",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
":slo_id"
],
"query": [
{
"key": "with_configured_alert_ids",
"value": "true",
"description": "Get the IDs of SLO monitors that reference this SLO."
}
],
"variable": [
{
"key": "slo_id"
}
]
}
},
"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": "Not found",
"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/slo/:slo_id?with_configured_alert_ids=true",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
":slo_id"
],
"query": [
{
"key": "with_configured_alert_ids",
"value": "true",
"description": "Get the IDs of SLO monitors that reference this SLO."
}
],
"variable": [
{
"key": "slo_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/slo/:slo_id?with_configured_alert_ids=true",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
":slo_id"
],
"query": [
{
"key": "with_configured_alert_ids",
"value": "true",
"description": "Get the IDs of SLO monitors that reference this SLO."
}
],
"variable": [
{
"key": "slo_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}"
}
]
}