Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Payload
string ls_Timestamp
string ls_V_type
string ls_ResultCount
string ls_PagedResultsCookie
string ls_TotalPagedResultsPolicy
string ls_TotalPagedResults
string ls_RemainingPagedResults
integer i
integer li_Count_i
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_QueryParams = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject")
loo_QueryParams.UpdateString("source","{{auditSource}}")
loo_QueryParams.UpdateString("_prettyPrint","true")
loo_Http.SetRequestHeader("x-api-secret","{{logApiSecret}}")
loo_Http.SetRequestHeader("x-api-key","{{logApiKey}}")
loo_Resp = loo_Http.QuickRequestParams("GET","https://<tenant-name>.forgeblocks.com/monitoring/logs/tail",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_QueryParams
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_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
ls_ResultCount = loo_JResp.StringOf("resultCount")
ls_PagedResultsCookie = loo_JResp.StringOf("pagedResultsCookie")
ls_TotalPagedResultsPolicy = loo_JResp.StringOf("totalPagedResultsPolicy")
ls_TotalPagedResults = loo_JResp.StringOf("totalPagedResults")
ls_RemainingPagedResults = loo_JResp.StringOf("remainingPagedResults")
i = 0
li_Count_i = loo_JResp.SizeOfArray("result")
do while i < li_Count_i
loo_JResp.I = i
ls_Payload = loo_JResp.StringOf("result[i].payload")
ls_Timestamp = loo_JResp.StringOf("result[i].timestamp")
ls_V_type = loo_JResp.StringOf("result[i].type")
i = i + 1
loop
destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -G -d "source=%7B%7BauditSource%7D%7D"
-d "_prettyPrint=true"
-H "x-api-key: {{logApiKey}}"
-H "x-api-secret: {{logApiSecret}}"
https://<tenant-name>.forgeblocks.com/monitoring/logs/tail
Postman Collection Item JSON
{
"name": "Step 3: Tail the Audit Logs for a Source",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const jsonData = JSON.parse(responseBody);",
"if(jsonData.pagedResultsCookie && jsonData.pagedResultsCookie != \"\"){",
" pm.globals.set(\"pagedResultsCookie\", jsonData.pagedResultsCookie);",
"}",
"",
"// Tests",
"",
"pm.test(\"Status code is 200.\", () => {",
" pm.expect(pm.response.code).to.eql(200);",
"});",
"",
"pm.test(\"Response contains results\", function () {",
" pm.expect(jsonData).to.have.any.keys('resultCount', 'result');",
"});",
"",
"pm.test(\"Response contains pagedResultsCookie\", function () {",
" pm.expect(jsonData).to.have.any.keys('pagedResultsCookie');",
"});"
],
"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/tail?source={{auditSource}}&_prettyPrint=true",
"host": [
"{{platformUrl}}"
],
"path": [
"monitoring",
"logs",
"tail"
],
"query": [
{
"key": "source",
"value": "{{auditSource}}"
},
{
"key": "_prettyPrint",
"value": "true"
}
]
},
"description": "Tail log events"
},
"response": [
{
"name": "List of log events",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/logs/tail?source=<string>&_pagedResultsCookie=<string>&_prettyPrint=false",
"host": [
"{{baseUrl}}"
],
"path": [
"logs",
"tail"
],
"query": [
{
"key": "source",
"value": "<string>"
},
{
"key": "_pagedResultsCookie",
"value": "<string>"
},
{
"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{\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}"
}
]
}