Back to Collection Items
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' 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")
set http = CreateObject("Chilkat.Http")
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set queryParams = CreateObject("Chilkat.JsonObject")
success = queryParams.UpdateString("source","{{auditSource}}")
success = queryParams.UpdateInt("_pageSize",10)
success = queryParams.UpdateString("_prettyPrint","true")
http.SetRequestHeader "x-api-secret","{{logApiSecret}}"
http.SetRequestHeader "x-api-key","{{logApiKey}}"
' resp is a Chilkat.HttpResponse
Set resp = http.QuickRequestParams("GET","https://<tenant-name>.forgeblocks.com/monitoring/logs",queryParams)
If (http.LastMethodSuccess = 0) Then
outFile.WriteLine(http.LastErrorText)
WScript.Quit
End If
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder")
set sbResponseBody = CreateObject("Chilkat.StringBuilder")
success = resp.GetBodySb(sbResponseBody)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set jResp = CreateObject("Chilkat.JsonObject")
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0
outFile.WriteLine("Response Body:")
outFile.WriteLine(jResp.Emit())
respStatusCode = resp.StatusCode
outFile.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
outFile.WriteLine("Response Header:")
outFile.WriteLine(resp.Header)
outFile.WriteLine("Failed.")
WScript.Quit
End If
' 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
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")
Do While i < count_i
jResp.I = i
payload = jResp.StringOf("result[i].payload")
timestamp = jResp.StringOf("result[i].timestamp")
v_type = jResp.StringOf("result[i].type")
i = i + 1
Loop
outFile.Close
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}"
}
]
}