Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *Category;
int Created_at;
const wchar_t *v_Email;
const wchar_t *Handle;
const wchar_t *Name;
const wchar_t *Description;
int Duration;
int v_End;
int Modified_at;
const wchar_t *ModifierEmail;
const wchar_t *ModifierHandle;
const wchar_t *ModifierName;
const wchar_t *Rrule;
const wchar_t *Slo_id;
int Start;
const wchar_t *Timezone;
const wchar_t *Id;
const wchar_t *v_Type;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "data": {
// "attributes": {
// "category": "Scheduled Maintenance",
// "description": "nisi ",
// "duration": 3600,
// "end": 1600000000,
// "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
// "start": 1600000000,
// "timezone": "UTC"
// },
// "type": "correction"
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"data.attributes.category",L"Scheduled Maintenance");
CkJsonObjectW_UpdateString(json,L"data.attributes.description",L"nisi ");
CkJsonObjectW_UpdateInt(json,L"data.attributes.duration",3600);
CkJsonObjectW_UpdateInt(json,L"data.attributes.end",1600000000);
CkJsonObjectW_UpdateString(json,L"data.attributes.rrule",L"FREQ=DAILY;INTERVAL=10;COUNT=5");
CkJsonObjectW_UpdateInt(json,L"data.attributes.start",1600000000);
CkJsonObjectW_UpdateString(json,L"data.attributes.timezone",L"UTC");
CkJsonObjectW_UpdateString(json,L"data.type",L"correction");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"PATCH",L"https://api.app.ddog-gov.com/api/v1/slo/correction/:slo_correction_id",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
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(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "attributes": {
// "category": "Scheduled Maintenance",
// "created_at": 11806311,
// "creator": {
// "email": "dolor nisi",
// "handle": "la",
// "name": "in quis est cillum"
// },
// "description": "nostrud amet ea exercitation",
// "duration": 3600,
// "end": 30790629,
// "modified_at": 77538107,
// "modifier": {
// "email": "pariatur nisi minim reprehenderit",
// "handle": "irure commodo",
// "name": "veniam"
// },
// "rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
// "slo_id": "incididunt qui velit sunt labore",
// "start": -34398281,
// "timezone": "eu id"
// },
// "id": "enim qui",
// "type": "correction"
// }
// }
// 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.
Category = CkJsonObjectW_stringOf(jResp,L"data.attributes.category");
Created_at = CkJsonObjectW_IntOf(jResp,L"data.attributes.created_at");
v_Email = CkJsonObjectW_stringOf(jResp,L"data.attributes.creator.email");
Handle = CkJsonObjectW_stringOf(jResp,L"data.attributes.creator.handle");
Name = CkJsonObjectW_stringOf(jResp,L"data.attributes.creator.name");
Description = CkJsonObjectW_stringOf(jResp,L"data.attributes.description");
Duration = CkJsonObjectW_IntOf(jResp,L"data.attributes.duration");
v_End = CkJsonObjectW_IntOf(jResp,L"data.attributes.end");
Modified_at = CkJsonObjectW_IntOf(jResp,L"data.attributes.modified_at");
ModifierEmail = CkJsonObjectW_stringOf(jResp,L"data.attributes.modifier.email");
ModifierHandle = CkJsonObjectW_stringOf(jResp,L"data.attributes.modifier.handle");
ModifierName = CkJsonObjectW_stringOf(jResp,L"data.attributes.modifier.name");
Rrule = CkJsonObjectW_stringOf(jResp,L"data.attributes.rrule");
Slo_id = CkJsonObjectW_stringOf(jResp,L"data.attributes.slo_id");
Start = CkJsonObjectW_IntOf(jResp,L"data.attributes.start");
Timezone = CkJsonObjectW_stringOf(jResp,L"data.attributes.timezone");
Id = CkJsonObjectW_stringOf(jResp,L"data.id");
v_Type = CkJsonObjectW_stringOf(jResp,L"data.type");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X PATCH
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"attributes": {
"category": "Scheduled Maintenance",
"description": "nisi ",
"duration": 3600,
"end": 1600000000,
"rrule": "FREQ=DAILY;INTERVAL=10;COUNT=5",
"start": 1600000000,
"timezone": "UTC"
},
"type": "correction"
}
}'
https://api.app.ddog-gov.com/api/v1/slo/correction/:slo_correction_id
Postman Collection Item JSON
{
"name": "Update an SLO correction",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_id",
"value": "tempor Ut sed velit"
}
]
},
"description": "Update the specified SLO correction object."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"created_at\": 11806311,\n \"creator\": {\n \"email\": \"dolor nisi\",\n \"handle\": \"la\",\n \"name\": \"in quis est cillum\"\n },\n \"description\": \"nostrud amet ea exercitation\",\n \"duration\": 3600,\n \"end\": 30790629,\n \"modified_at\": 77538107,\n \"modifier\": {\n \"email\": \"pariatur nisi minim reprehenderit\",\n \"handle\": \"irure commodo\",\n \"name\": \"veniam\"\n },\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"slo_id\": \"incididunt qui velit sunt labore\",\n \"start\": -34398281,\n \"timezone\": \"eu id\"\n },\n \"id\": \"enim qui\",\n \"type\": \"correction\"\n }\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_id"
}
]
}
},
"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": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_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": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_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": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"category\": \"Scheduled Maintenance\",\n \"description\": \"nisi \",\n \"duration\": 3600,\n \"end\": 1600000000,\n \"rrule\": \"FREQ=DAILY;INTERVAL=10;COUNT=5\",\n \"start\": 1600000000,\n \"timezone\": \"UTC\"\n },\n \"type\": \"correction\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo/correction/:slo_correction_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo",
"correction",
":slo_correction_id"
],
"variable": [
{
"key": "slo_correction_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}"
}
]
}