Add Audit Log

Estimated reading: 2 minutes 338 views

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

ObjectDescription
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.groupCan be user role group or department name in company structure.
actor.ipUser’s device IP address.
actor.locationUser’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.
timezoneTimezone 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.
pathWebpage or application module where the object or underlying resource that is being changed by user.
descA human readable description of the action taken. Can be a plain text description or in JSON format.
tagTag for categorizing audit log. Separate with comma.
Bold and object with * is mandatory

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.

ActionUsage
createWhen user create or add new data
accessWhen user open or access a view/page
updateWhen user edit/modify a data
editWhen user edit/modify a data
deleteWhen user delete a data
registerNew user registered
login_failedUser failed to login
login_successSuccessful user login
logoutUser ended the session
password_resetUser resetting or changing password
Share this Doc

Add Audit Log

Or copy link

CONTENTS