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 json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *strVal;
const wchar_t *v_Type;
const wchar_t *Name;
const wchar_t *Query;
const wchar_t *Storage_account;
const wchar_t *Container;
const wchar_t *Tenant_id;
const wchar_t *Client_id;
const wchar_t *DestinationType;
const wchar_t *Path;
const wchar_t *Region;
BOOL Include_tags;
const wchar_t *Rehydration_max_scan_size_in_gb;
const wchar_t *State;
const wchar_t *Id;
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();
// 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": {
// "type": "archives",
// "attributes": {
// "name": "<string>",
// "query": "<string>",
// "destination": {
// "storage_account": "<string>",
// "container": "<string>",
// "integration": {
// "tenant_id": "<string>",
// "client_id": "<string>"
// },
// "type": "azure",
// "path": "<string>",
// "region": "<string>"
// },
// "include_tags": false,
// "rehydration_max_scan_size_in_gb": "<long>",
// "rehydration_tags": [
// "<string>",
// "<string>"
// ]
// }
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"data.type",L"archives");
CkJsonObjectW_UpdateString(json,L"data.attributes.name",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.query",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.storage_account",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.container",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.integration.tenant_id",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.integration.client_id",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.type",L"azure");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.path",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.destination.region",L"<string>");
CkJsonObjectW_UpdateBool(json,L"data.attributes.include_tags",FALSE);
CkJsonObjectW_UpdateString(json,L"data.attributes.rehydration_max_scan_size_in_gb",L"<long>");
CkJsonObjectW_UpdateString(json,L"data.attributes.rehydration_tags[0]",L"<string>");
CkJsonObjectW_UpdateString(json,L"data.attributes.rehydration_tags[1]",L"<string>");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpW_PostJson3(http,L"https://api.app.ddog-gov.com/api/v2/logs/config/archives",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
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(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "type": "archives",
// "attributes": {
// "name": "<string>",
// "query": "<string>",
// "destination": {
// "storage_account": "<string>",
// "container": "<string>",
// "integration": {
// "tenant_id": "<string>",
// "client_id": "<string>"
// },
// "type": "azure",
// "path": "<string>",
// "region": "<string>"
// },
// "include_tags": false,
// "rehydration_max_scan_size_in_gb": "<long>",
// "rehydration_tags": [
// "<string>",
// "<string>"
// ],
// "state": "FAILING"
// },
// "id": "<string>"
// }
// }
// 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_Type = CkJsonObjectW_stringOf(jResp,L"data.type");
Name = CkJsonObjectW_stringOf(jResp,L"data.attributes.name");
Query = CkJsonObjectW_stringOf(jResp,L"data.attributes.query");
Storage_account = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.storage_account");
Container = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.container");
Tenant_id = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.integration.tenant_id");
Client_id = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.integration.client_id");
DestinationType = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.type");
Path = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.path");
Region = CkJsonObjectW_stringOf(jResp,L"data.attributes.destination.region");
Include_tags = CkJsonObjectW_BoolOf(jResp,L"data.attributes.include_tags");
Rehydration_max_scan_size_in_gb = CkJsonObjectW_stringOf(jResp,L"data.attributes.rehydration_max_scan_size_in_gb");
State = CkJsonObjectW_stringOf(jResp,L"data.attributes.state");
Id = CkJsonObjectW_stringOf(jResp,L"data.id");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.attributes.rehydration_tags");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"data.attributes.rehydration_tags[i]");
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"type": "archives",
"attributes": {
"name": "<string>",
"query": "<string>",
"destination": {
"storage_account": "<string>",
"container": "<string>",
"integration": {
"tenant_id": "<string>",
"client_id": "<string>"
},
"type": "azure",
"path": "<string>",
"region": "<string>"
},
"include_tags": false,
"rehydration_max_scan_size_in_gb": "<long>",
"rehydration_tags": [
"<string>",
"<string>"
]
}
}
}'
https://api.app.ddog-gov.com/api/v2/logs/config/archives
Postman Collection Item JSON
{
"name": "Create an archive",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/logs/config/archives",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"logs",
"config",
"archives"
]
},
"description": "Create an archive in your organization."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "POST",
"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 \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/logs/config/archives",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"logs",
"config",
"archives"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ],\n \"state\": \"FAILING\"\n },\n \"id\": \"<string>\"\n }\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "POST",
"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 \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/logs/config/archives",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"logs",
"config",
"archives"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "POST",
"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 \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/logs/config/archives",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"logs",
"config",
"archives"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "POST",
"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 \"type\": \"archives\",\n \"attributes\": {\n \"name\": \"<string>\",\n \"query\": \"<string>\",\n \"destination\": {\n \"storage_account\": \"<string>\",\n \"container\": \"<string>\",\n \"integration\": {\n \"tenant_id\": \"<string>\",\n \"client_id\": \"<string>\"\n },\n \"type\": \"azure\",\n \"path\": \"<string>\",\n \"region\": \"<string>\"\n },\n \"include_tags\": false,\n \"rehydration_max_scan_size_in_gb\": \"<long>\",\n \"rehydration_tags\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/logs/config/archives",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"logs",
"config",
"archives"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
}
]
}