Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject queryParams;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *payload;
const char *timestamp;
const char *v_type;
const char *resultCount;
const char *pagedResultsCookie;
const char *totalPagedResultsPolicy;
const char *totalPagedResults;
const char *remainingPagedResults;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
queryParams = CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,"source","{{auditSource}}");
CkJsonObject_UpdateInt(queryParams,"_pageSize",10);
CkJsonObject_UpdateString(queryParams,"_prettyPrint","true");
CkHttp_SetRequestHeader(http,"x-api-secret","{{logApiSecret}}");
CkHttp_SetRequestHeader(http,"x-api-key","{{logApiKey}}");
resp = CkHttp_QuickRequestParams(http,"GET","https://<tenant-name>.forgeblocks.com/monitoring/logs",queryParams);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "result": [
// {
// "payload": "<object>",
// "timestamp": "<dateTime>",
// "type": "<string>"
// },
// {
// "payload": "<object>",
// "timestamp": "<dateTime>",
// "type": "<string>"
// }
// ],
// "resultCount": "<integer>",
// "pagedResultsCookie": "<string>",
// "totalPagedResultsPolicy": "<string>",
// "totalPagedResults": "<integer>",
// "remainingPagedResults": "<integer>"
// }
// 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.
resultCount = CkJsonObject_stringOf(jResp,"resultCount");
pagedResultsCookie = CkJsonObject_stringOf(jResp,"pagedResultsCookie");
totalPagedResultsPolicy = CkJsonObject_stringOf(jResp,"totalPagedResultsPolicy");
totalPagedResults = CkJsonObject_stringOf(jResp,"totalPagedResults");
remainingPagedResults = CkJsonObject_stringOf(jResp,"remainingPagedResults");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"result");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
payload = CkJsonObject_stringOf(jResp,"result[i].payload");
timestamp = CkJsonObject_stringOf(jResp,"result[i].timestamp");
v_type = CkJsonObject_stringOf(jResp,"result[i].type");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -G -d "source=%7B%7BauditSource%7D%7D"
-d "_pageSize=10"
-d "_prettyPrint=true"
-H "x-api-key: {{logApiKey}}"
-H "x-api-secret: {{logApiSecret}}"
https://<tenant-name>.forgeblocks.com/monitoring/logs
Postman Collection Item JSON
{
"name": "Step 2: Get Audit Logs for a Source",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const JSONResponse = pm.response.json();",
"",
"// Tests",
"",
"pm.test(\"Status code is 200.\", () => {",
" pm.expect(pm.response.code).to.eql(200);",
"});",
"",
"pm.test(\"Response contains resultCount or result\", function () {",
" pm.expect(JSONResponse).to.have.any.keys('resultCount', 'result');",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{logApiKey}}",
"type": "text"
},
{
"key": "x-api-secret",
"value": "{{logApiSecret}}",
"type": "text"
}
],
"url": {
"raw": "{{platformUrl}}/monitoring/logs?source={{auditSource}}&_pageSize=10&_prettyPrint=true",
"host": [
"{{platformUrl}}"
],
"path": [
"monitoring",
"logs"
],
"query": [
{
"key": "source",
"value": "{{auditSource}}"
},
{
"key": "beginTime",
"value": "2020-08-27T15:10:36.177Z",
"disabled": true
},
{
"key": "endTime",
"value": "{{$isoTimestamp}}",
"disabled": true
},
{
"key": "_pageSize",
"value": "10"
},
{
"key": "_prettyPrint",
"value": "true"
}
]
},
"description": "Get log events"
},
"response": [
{
"name": "List of log events",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/logs?source=<string>&beginTime=<dateTime>&endTime=<dateTime>&_pageSize=<integer>&_pagedResultsCookie=<string>&_prettyPrint=false&_sortKeys=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"logs"
],
"query": [
{
"key": "source",
"value": "<string>"
},
{
"key": "beginTime",
"value": "<dateTime>"
},
{
"key": "endTime",
"value": "<dateTime>"
},
{
"key": "_pageSize",
"value": "<integer>"
},
{
"key": "_pagedResultsCookie",
"value": "<string>"
},
{
"key": "_prettyPrint",
"value": "false"
},
{
"key": "_sortKeys",
"value": "<string>"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"result\": [\n\t\t{\n\t\t\t\"payload\": \"<object>\",\n\t\t\t\"timestamp\": \"<dateTime>\",\n\t\t\t\"type\": \"<string>\"\n\t\t},\n\t\t{\n\t\t\t\"payload\": \"<object>\",\n\t\t\t\"timestamp\": \"<dateTime>\",\n\t\t\t\"type\": \"<string>\"\n\t\t}\n\t],\n\t\"resultCount\": \"<integer>\",\n\t\"pagedResultsCookie\": \"<string>\",\n\t\"totalPagedResultsPolicy\": \"<string>\",\n\t\"totalPagedResults\": \"<integer>\",\n\t\"remainingPagedResults\": \"<integer>\"\n}"
}
]
}