Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global_Ref.html">Global Unlock Sample for sample code.
http := chilkat.NewHttp()
var success bool
queryParams := chilkat.NewJsonObject()
queryParams.UpdateString("source","{{auditSource}}")
queryParams.UpdateString("_prettyPrint","true")
http.SetRequestHeader("x-api-secret","{{logApiSecret}}")
http.SetRequestHeader("x-api-key","{{logApiKey}}")
resp := http.QuickRequestParams("GET","https://<tenant-name>.forgeblocks.com/monitoring/logs/tail",queryParams)
if http.LastMethodSuccess() == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
queryParams.DisposeJsonObject()
return
}
sbResponseBody := chilkat.NewStringBuilder()
resp.GetBodySb(sbResponseBody)
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := resp.StatusCode()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(resp.Header())
fmt.Println("Failed.")
resp.DisposeHttpResponse()
http.DisposeHttp()
queryParams.DisposeJsonObject()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
resp.DisposeHttpResponse()
// 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
var payload *string = new(string)
var timestamp *string = new(string)
var v_type *string = new(string)
resultCount := jResp.StringOf("resultCount")
pagedResultsCookie := jResp.StringOf("pagedResultsCookie")
totalPagedResultsPolicy := jResp.StringOf("totalPagedResultsPolicy")
totalPagedResults := jResp.StringOf("totalPagedResults")
remainingPagedResults := jResp.StringOf("remainingPagedResults")
i := 0
count_i := jResp.SizeOfArray("result")
for i < count_i {
jResp.SetI(i)
payload = jResp.StringOf("result[i].payload")
timestamp = jResp.StringOf("result[i].timestamp")
v_type = jResp.StringOf("result[i].type")
i = i + 1
}
http.DisposeHttp()
queryParams.DisposeJsonObject()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
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}"
}
]
}