Add Audit Log
Our API is very simple and easy to implement. With a single API request you can add an audit log with only 4 minimum object for audit logging. In case you need to log more detailed object, you can add them to the JSON as defined in the documentation.
API Endpoint
https://api.logzab.com/v1/addTrail
JSON Request
{
'apiKey' : 'xxx-yyy-zzz',
'actor' : {'unique_id' : '4123',
'name' : 'John Doe',
'group' : 'IT Dept',
'ip' : '36.68.17.182',
'device' : 'Macbook Pro 13',
'location' : 'Jakarta, ID'
},
'object' : 'Employee',
'timezone' : 'Asia/Jakarta',
'action' : 'update',
'path' : 'hris.local.net/employee',
'desc' : 'Updating employee data: Jackson',
'tag' : '#hris #webapp'
}
Code Examples
curl --request POST \
--url https://api.logzab.com/v1/addTrail \
--header 'Content-Type: application/json' \
--data '{
"apiKey" : "xxx-yyy-zzz",
"actor" : {"unique_id" : "4123",
"name" : "John Doe",
"group" : "IT Dept",
"ip" : "36.68.17.182",
"device" : "Macbook Pro 13",
"location" : "Jakarta, ID"
},
"object" : "Employee",
"timezone" : "Asia/Jakarta",
"action" : "update",
"path" : "hris.local.net/employee",
"desc" : "Updating employee data: Jackson",
"tag" : "#hris #webapp"
}'
import http.client
conn = http.client.HTTPConnection("api.logzab.com")
payload = "{
'apiKey' : 'xxx-yyy-zzz',
'actor' : {'unique_id' : '4123',
'name' : 'John Doe',
'group' : 'IT Dept',
'ip' : '36.68.17.182',
'device' : 'Macbook Pro 13',
'location' : 'Jakarta, ID'
},
'object' : 'Employee',
'timezone' : 'Asia/Jakarta',
'action' : 'update',
'path' : 'hris.local.net/employee',
'desc' : 'Updating employee data: Jackson',
'tag' : '#hris #webapp'
}"
headers = { 'Content-Type': "application/json" }
conn.request("POST", "/v1/addTrail", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.logzab.com/v1/addTrail",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{
'apiKey' : 'xxx-yyy-zzz',
'actor' : {'unique_id' : '4123',
'name' : 'John Doe',
'group' : 'IT Dept',
'ip' : '36.68.17.182',
'device' : 'Macbook Pro 13',
'location' : 'Jakarta, ID'
},
'object' : 'Employee',
'timezone' : 'Asia/Jakarta',
'action' : 'update',
'path' : 'hris.local.net/employee',
'desc' : 'Updating employee data: Jackson',
'tag' : '#hris #webapp'
}",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
List of JSON Objects
Object | Description |
---|---|
apiKey * | API key from LogZab Dashboard Panel. |
actor.unique_id * | Unique identifier for app user. Can be uuid, employee ID, app user ID, gov ID, etc. flexible depends on your apps and business need. |
actor.name * | Human readable user name. |
actor.group | Can be user role group or department name in company structure. |
actor.ip | User’s device IP address. |
actor.location | User’s location when accessing app |
object * | The object or underlying resource that is being changed as well as the fields that include a key value for the new state of the target. |
timezone | Timezone with tz format. Default is UTC (GMT+0). |
action * | The way in which the object was changed (the verb). Action reference are defined below this table. |
path | Webpage or application module where the object or underlying resource that is being changed by user. |
desc | A human readable description of the action taken. Can be a plain text description or in JSON format. |
tag | Tag for categorizing audit log. Separate with comma. |
Action References
References in below table is recommended but not strict. You can insert audit log with custom action even its not defined by the documentation. Here is list of known action reference.
Action | Usage |
---|---|
create | When user create or add new data |
access | When user open or access a view/page |
update | When user edit/modify a data |
edit | When user edit/modify a data |
delete | When user delete a data |
register | New user registered |
login_failed | User failed to login |
login_success | Successful user login |
logout | User ended the session |
password_reset | User resetting or changing password |