Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
var queryParams = new chilkat.JsonObject();
queryParams.UpdateString("_prettyPrint","true");
http.SetRequestHeader("x-api-secret","{{logApiSecret}}");
http.SetRequestHeader("x-api-key","{{logApiKey}}");
// resp: HttpResponse
var resp = http.QuickRequestParams("GET","https://<tenant-name>.forgeblocks.com/monitoring/logs/sources",queryParams);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
var sbResponseBody = new chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
var jResp = new chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
console.log("Response Body:");
console.log(jResp.Emit());
var respStatusCode = resp.StatusCode;
console.log("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
console.log("Response Header:");
console.log(resp.Header);
console.log("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "result": [
// "<string>",
// "<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
var strVal;
var resultCount = jResp.StringOf("resultCount");
var pagedResultsCookie = jResp.StringOf("pagedResultsCookie");
var totalPagedResultsPolicy = jResp.StringOf("totalPagedResultsPolicy");
var totalPagedResults = jResp.StringOf("totalPagedResults");
var remainingPagedResults = jResp.StringOf("remainingPagedResults");
var i = 0;
var count_i = jResp.SizeOfArray("result");
while (i < count_i) {
jResp.I = i;
strVal = jResp.StringOf("result[i]");
i = i+1;
}
}
chilkatExample();
Curl Command
curl -G -d "_prettyPrint=true"
-H "x-api-key: {{logApiKey}}"
-H "x-api-secret: {{logApiSecret}}"
https://<tenant-name>.forgeblocks.com/monitoring/logs/sources
Postman Collection Item JSON
{
"name": "Step 1: Get Audit Log Sources",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const JSONResponse = JSON.parse(responseBody);",
"",
"// Did request contain results?",
"if(JSONResponse.resultCount && JSONResponse.resultCount > 0)",
"{",
" // Set `managedUserId` variable",
" pm.globals.set(\"auditSource\", JSONResponse.result[0]);",
"}",
"else",
"{",
" pm.globals.set(\"auditSource\", \"none_found\"); ",
"}",
"",
"",
"// Tests",
"",
"pm.test(\"Status code is 200.\", () => {",
" pm.expect(pm.response.code).to.eql(200);",
"});",
"",
"pm.test(\"Response contains tokenId or authId\", 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}}"
},
{
"key": "x-api-secret",
"value": "{{logApiSecret}}",
"type": "text"
}
],
"url": {
"raw": "{{platformUrl}}/monitoring/logs/sources?_prettyPrint=true",
"host": [
"{{platformUrl}}"
],
"path": [
"monitoring",
"logs",
"sources"
],
"query": [
{
"key": "_prettyPrint",
"value": "true"
}
]
},
"description": "Get log sources"
},
"response": [
{
"name": "List of log sources",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/logs/sources?_pageSize=<integer>&_pagedResouresOffset=<integer>&_prettyPrint=false",
"host": [
"{{baseUrl}}"
],
"path": [
"logs",
"sources"
],
"query": [
{
"key": "_pageSize",
"value": "<integer>"
},
{
"key": "_pagedResouresOffset",
"value": "<integer>"
},
{
"key": "_prettyPrint",
"value": "false"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n\t\"result\": [\n\t\t\"<string>\",\n\t\t\"<string>\"\n\t],\n\t\"resultCount\": \"<integer>\",\n\t\"pagedResultsCookie\": \"<string>\",\n\t\"totalPagedResultsPolicy\": \"<string>\",\n\t\"totalPagedResults\": \"<integer>\",\n\t\"remainingPagedResults\": \"<integer>\"\n}"
}
]
}