# Audit Log REST API

The Audit Log REST API can retrieve data from the audit logs for your _Lifecycle_ instance for the specified time period. The response will contain lines of text from the audit logs in chronologically ascending order.

**Permissions Required:** Access Audit Log.

Users assigned to the built-in System Administrator role have audit log access by default. To configure a custom role that allows users to access the audit logs:

1. In _System Preferences_, go to the Roles section and click _Create Role_.
2. Under the _Permissions_ section, select _Access Audit Log_.
3. Assign the role to an organization.

- A role is not effective until it is associated with an organization.
   - To make the role apply globally, assign it at the Root Organization level.

For more information refer to [Roles and Permissions](https://help.sonatype.com/en/role-management.html).

## Methods Supported

### GET

```
GET /api/v2/auditLogs?startUtcDate={startUtcDate}&endUtcDate={endUtcDate}
```

### Input Parameters

| Parameter      | Required | Description                                                                                      |
|----------------|----------|--------------------------------------------------------------------------------------------------|
| startUtcDate   | Yes      | The start date in UTC format (yyyy-mm-dd). Events from this date onwards (inclusive) will be returned in the response. |
| endUtcDate     | Yes      | The end date in UTC format (yyyy-mm-dd). Events up to this date (inclusive) will be returned in the response.          |

### Example

```
curl -u admin:admin123 'http://localhost:8070/api/v2/auditLogs?startUtcDate=2024-03-20&endUtcDate=2024-03-21'
```

where 2024-03-20 is the startUtcDate and 2024-03-21 is the endUtcDate.

The REST API will use the same time zone as that set for the _Lifecycle_ instance, i.e. UTC.

### Response

A successful GET request will generate a response consisting of lines from audit logs in chronologically ascending order.

```
{"timestamp":"2024-03-21T10:39:44.896-03:00","username":"*SYSTEM","domain":"server","type":"start","data":{"serverInstanceId":"7449fbe6-0fb1-4b71-b358-400cc9df673d","serverConfigurationFile":"/home/config.yml","serverRelease":"175.0-SNAPSHOT","serverBuild":"build-number","processOwner":"johndoe"}}

{"timestamp":"2024-03-21T11:58:14.233-03:00","remoteIpAddress":"127.0.0.1","userAgent":"curl/7.81.0","username":"admin","domain":"audit-log","type":"export","error":"bad-request"}
```

### Related Links:

[Audit logging configuration](https://help.sonatype.com/en/logging-configuration.html#audit-log-162302) for more information on audit events.

[Lifecycle system logs](https://help.sonatype.com/en/audit-log.html) for more information on audit logs.
