> For the complete documentation index, see [llms.txt](https://faleddo.gitbook.io/logzab/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faleddo.gitbook.io/logzab/api-endpoints/add-audit-log.md). Agents can also search and read this documentation through its [MCP server](https://faleddo.gitbook.io/logzab/~gitbook/mcp).

# Add Audit Log

### **JSON Request Body Definitions**

JSON structure below defines any audit log data that can be send to LogZab.

{% code title="JSON Format" lineNumbers="true" %}

```json
{
	"apiKey":"your-api-key",
	"actor":{
		"unique_id"	:"",
		"name"		:"",
		"group"		:"",
		"ip"		:"",
		"device"	:"",
		"location"	:""
	},
	"object":"",
	"action":"",
	"timezone":"",
	"path":"",
	"desc":"",
	"tag":""
}
```

{% endcode %}

JSON object definitions. Bold object is mandatory object to send.

| Object Name      | Type                   | Description                                                                               |
| ---------------- | ---------------------- | ----------------------------------------------------------------------------------------- |
| **apiKey**       | string. mandatory.     | Your API key                                                                              |
| actor.unique\_id | string. optional.      | Can be user ID, GUID, etc.                                                                |
| **actor.name**   | string. mandatory      | User name who take action on system.                                                      |
| actor.group      | string. optional.      | User's group role or branch.                                                              |
| actor.ip         | string. optional.      | User's IP address.                                                                        |
| actor.device     | string. optional.      | User's device type.                                                                       |
| actor.location   | string. optional.      | User's location.                                                                          |
| **object**       | string. mandatory.     | Object where user is working on.                                                          |
| **action**       | string. mandatory.     | Verbs. What user is doing. Commonly one this system action: create, access, edit, delete. |
| timezone         | string. optional.      | User's timezone. Default is UTC (GMT+0).                                                  |
| **path**         | string. mandatory.     | App path, page, or URL name where user is doing the action.                               |
| desc             | string/json. optional. | Detailed description about what user is doing.                                            |
| tag              | string. optional.      | Log tag.                                                                                  |

Example JSON format to add audit log information:

{% code title="JSON Example" lineNumbers="true" %}

```json
 {
	"apiKey":"aaa-bbb-ccc",
	"actor":{
		"unique_id":"155",
		"name":"Faleddo",
		"group":"IT Dept.",
		"ip":"192.168.32.5",
		"device":"Macbook Pro 13.1",
		"location":"Main Branch"
	},
	"object":"employee",
	"action":"edit",
	"timezone":"Asia/Jakarta",
	"path":"/hcis/employee/all_data",
	"desc":"Edit employee address: John Doe. From 'Orange Street 53' to 'Wall st. 77'",
	"tag":"info"
}
```

{% endcode %}

### Code Example

{% tabs %}
{% tab title="CURL" %}

```shell
curl --request POST \
  --url https://api.logzab.com/v1/addTrail \
  --header 'Content-Type: application/json' \
  --data '{
	"apiKey":"aaa-bbb-ccc",
	"actor":{
		"unique_id":"155",
		"name":"Faleddo",
		"group":"IT Dept.",
		"ip":"192.168.32.5",
		"device":"Macbook Pro 13.1",
		"location":"Main Branch"
	},
	"object":"employee",
	"action":"edit",
	"timezone":"Asia/Jakarta",
	"path":"/hcis/employee/all_data",
	"desc":"Edit employee address: John Doe. From '\''Orange Street 53'\'' to '\''Wall st. 77'\''",
	"tag":"info"
}'
```

{% endtab %}

{% tab title="JS" %}

```javascript
import axios from "axios";

const options = {
  method: 'POST',
  url: 'https://api.logzab.com/v1/addTrail',
  headers: {'Content-Type': 'application/json'},
  data: {
    apiKey: 'aaa-bbb-ccc',
    actor: {
      unique_id: '155',
      name: 'Faleddo',
      group: 'IT Dept.',
      ip: '192.168.32.5',
      device: 'Macbook Pro 13.1',
      location: 'Main Branch'
    },
    object: 'employee',
    action: 'edit',
    timezone: 'Asia/Jakarta',
    path: '/hcis/employee/all_data',
    desc: 'Edit employee address: John Doe. From \'Orange Street 53\' to \'Wall st. 77\'',
    tag: 'info'
  }
};

axios.request(options).then(function (response) {
  console.log(response.data);
}).catch(function (error) {
  console.error(error);
});
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append('{
	"apiKey":"aaa-bbb-ccc",
	"actor":{
		"unique_id":"155",
		"name":"Faleddo",
		"group":"IT Dept.",
		"ip":"192.168.32.5",
		"device":"Macbook Pro 13.1",
		"location":"Main Branch"
	},
	"object":"employee",
	"action":"edit",
	"timezone":"Asia/Jakarta",
	"path":"/hcis/employee/all_data",
	"desc":"Edit employee address: John Doe. From 'Orange Street 53' to 'Wall st. 77'",
	"tag":"info"
}');

$request->setRequestUrl('https://api.logzab.com/v1/addTrail');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders([
  'Content-Type' => 'application/json'
]);

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://api.logzab.com/v1/addTrail"

	payload := strings.NewReader("{\n\t\"apiKey\":\"aaa-bbb-ccc\",\n\t\"actor\":{\n\t\t\"unique_id\":\"155\",\n\t\t\"name\":\"Faleddo\",\n\t\t\"group\":\"IT Dept.\",\n\t\t\"ip\":\"192.168.32.5\",\n\t\t\"device\":\"Macbook Pro 13.1\",\n\t\t\"location\":\"Main Branch\"\n\t},\n\t\"object\":\"employee\",\n\t\"action\":\"edit\",\n\t\"timezone\":\"Asia/Jakarta\",\n\t\"path\":\"/hcis/employee/all_data\",\n\t\"desc\":\"Edit employee address: John Doe. From 'Orange Street 53' to 'Wall st. 77'\",\n\t\"tag\":\"info\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="Swift" %}

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "apiKey": "aaa-bbb-ccc",
  "actor": [
    "unique_id": "155",
    "name": "Faleddo",
    "group": "IT Dept.",
    "ip": "192.168.32.5",
    "device": "Macbook Pro 13.1",
    "location": "Main Branch"
  ],
  "object": "employee",
  "action": "edit",
  "timezone": "Asia/Jakarta",
  "path": "/hcis/employee/all_data",
  "desc": "Edit employee address: John Doe. From 'Orange Street 53' to 'Wall st. 77'",
  "tag": "info"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.logzab.com/v1/addTrail")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.logzab.com/v1/addTrail"

payload = {
    "apiKey": "aaa-bbb-ccc",
    "actor": {
        "unique_id": "155",
        "name": "Faleddo",
        "group": "IT Dept.",
        "ip": "192.168.32.5",
        "device": "Macbook Pro 13.1",
        "location": "Main Branch"
    },
    "object": "employee",
    "action": "edit",
    "timezone": "Asia/Jakarta",
    "path": "/hcis/employee/all_data",
    "desc": "Edit employee address: John Doe. From 'Orange Street 53' to 'Wall st. 77'",
    "tag": "info"
}
headers = {"Content-Type": "application/json"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
```

{% endtab %}
{% endtabs %}
