Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loQueryParams
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcPayload
LOCAL lcTimestamp
LOCAL lcV_type
LOCAL lcResultCount
LOCAL lcPagedResultsCookie
LOCAL lcTotalPagedResultsPolicy
LOCAL lcTotalPagedResults
LOCAL lcRemainingPagedResults
LOCAL i
LOCAL lnCount_i
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loQueryParams = CreateObject('Chilkat.JsonObject')
loQueryParams.UpdateString("source","{{auditSource}}")
loQueryParams.UpdateString("_pagedResultsCookie","{{pagedResultsCookie}}")
loQueryParams.UpdateString("_prettyPrint","false")
loHttp.SetRequestHeader("x-api-secret","{{logApiSecret}}")
loHttp.SetRequestHeader("x-api-key","{{logApiKey}}")
loResp = loHttp.QuickRequestParams("GET","https://<tenant-name>.forgeblocks.com/monitoring/logs/tail",loQueryParams)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loQueryParams
CANCEL
ENDIF
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loResp
RELEASE loHttp
RELEASE loQueryParams
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
RELEASE loResp
* 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
lcResultCount = loJResp.StringOf("resultCount")
lcPagedResultsCookie = loJResp.StringOf("pagedResultsCookie")
lcTotalPagedResultsPolicy = loJResp.StringOf("totalPagedResultsPolicy")
lcTotalPagedResults = loJResp.StringOf("totalPagedResults")
lcRemainingPagedResults = loJResp.StringOf("remainingPagedResults")
i = 0
lnCount_i = loJResp.SizeOfArray("result")
DO WHILE i < lnCount_i
loJResp.I = i
lcPayload = loJResp.StringOf("result[i].payload")
lcTimestamp = loJResp.StringOf("result[i].timestamp")
lcV_type = loJResp.StringOf("result[i].type")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loQueryParams
RELEASE loSbResponseBody
RELEASE loJResp
Curl Command
curl -G -d "source=%7B%7BauditSource%7D%7D"
-d "_pagedResultsCookie=%7B%7BpagedResultsCookie%7D%7D"
-d "_prettyPrint=false"
-H "x-api-key: {{logApiKey}}"
-H "x-api-secret: {{logApiSecret}}"
https://<tenant-name>.forgeblocks.com/monitoring/logs/tail
Postman Collection Item JSON
{
"name": "Step 4: Tail the Audit Logs for a Source Since Last Request",
"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",
"type": "text",
"value": "{{logApiKey}}"
},
{
"key": "x-api-secret",
"type": "text",
"value": "{{logApiSecret}}"
}
],
"url": {
"raw": "{{platformUrl}}/monitoring/logs/tail?source={{auditSource}}&_pagedResultsCookie={{pagedResultsCookie}}&_prettyPrint=false",
"host": [
"{{platformUrl}}"
],
"path": [
"monitoring",
"logs",
"tail"
],
"query": [
{
"key": "source",
"value": "{{auditSource}}"
},
{
"key": "_pagedResultsCookie",
"value": "{{pagedResultsCookie}}"
},
{
"key": "_prettyPrint",
"value": "false"
}
]
},
"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}"
}
]
}