# Audit Logs

## Get Audit Log

`client.auditLogs.get(stringauditLogID, RequestOptionsoptions?): AuditLog`

**get** `/v1/audit_logs/{audit_log_id}`

Get an Audit Log entry

### Parameters

- `auditLogID: string`

### Returns

- `AuditLog`

  Audit log entry.

  - `id: string`

    Unique identifier for the audit log entry.

  - `action: string`

    The action that was performed.

  - `actor: AuditLogActor`

    The entity that performed the action.

    - `id: string`

      Unique identifier for the actor.

    - `name: string | null`

      Display name of the actor.

    - `type: AuditLogType`

      Type of actor.

      - `"user"`

      - `"api_key"`

  - `client_ip: string`

    Client IP address.

  - `created_at: string`

    When the action occurred.

  - `method: string`

    HTTP method of the request.

  - `path: string`

    Request path.

  - `status_code: number`

    HTTP status code of the response.

  - `user_agent: string`

    User agent string.

  - `target?: AuditLogTarget | null`

    The target resource of the action.

    - `id: string`

      Unique identifier for the target resource.

    - `type: string`

      Type of the target resource.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

const auditLog = await client.auditLogs.get('audit_log_id');

console.log(auditLog.id);
```

#### Response

```json
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "action": "vm.created",
  "actor": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "Alice Smith",
    "type": "user"
  },
  "client_ip": "203.0.113.1",
  "created_at": "2025-01-01T00:00:00Z",
  "method": "GET",
  "path": "/v1/compute/vms",
  "status_code": 200,
  "user_agent": "Mozilla/5.0",
  "target": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "type": "vm"
  }
}
```

## List Audit Logs

`client.auditLogs.list(AuditLogListParamsquery?, RequestOptionsoptions?): Cursor<AuditLog>`

**get** `/v1/audit_logs`

List Audit Log entries for an organization

### Parameters

- `query: AuditLogListParams`

  - `cursor?: string`

    Pagination cursor returned by a previous request

  - `limit?: number`

    Maximum number of items to return

### Returns

- `AuditLog`

  Audit log entry.

  - `id: string`

    Unique identifier for the audit log entry.

  - `action: string`

    The action that was performed.

  - `actor: AuditLogActor`

    The entity that performed the action.

    - `id: string`

      Unique identifier for the actor.

    - `name: string | null`

      Display name of the actor.

    - `type: AuditLogType`

      Type of actor.

      - `"user"`

      - `"api_key"`

  - `client_ip: string`

    Client IP address.

  - `created_at: string`

    When the action occurred.

  - `method: string`

    HTTP method of the request.

  - `path: string`

    Request path.

  - `status_code: number`

    HTTP status code of the response.

  - `user_agent: string`

    User agent string.

  - `target?: AuditLogTarget | null`

    The target resource of the action.

    - `id: string`

      Unique identifier for the target resource.

    - `type: string`

      Type of the target resource.

### Example

```typescript
import NirvanaLabs from '@nirvana-labs/nirvana';

const client = new NirvanaLabs({
  apiKey: process.env['NIRVANA_LABS_API_KEY'], // This is the default and can be omitted
});

// Automatically fetches more pages as needed.
for await (const auditLog of client.auditLogs.list()) {
  console.log(auditLog.id);
}
```

#### Response

```json
{
  "items": [
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "action": "vm.created",
      "actor": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "name": "Alice Smith",
        "type": "user"
      },
      "client_ip": "203.0.113.1",
      "created_at": "2025-01-01T00:00:00Z",
      "method": "GET",
      "path": "/v1/compute/vms",
      "status_code": 200,
      "user_agent": "Mozilla/5.0",
      "target": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "type": "vm"
      }
    }
  ],
  "pagination": {
    "next_cursor": "RhwniMT4B74siYZcPF8TnCdGI1l9rpPvg",
    "previous_cursor": "ARhwnmi1hA7wEbHbMjdYQlOB_ZusP4fYvw",
    "total_count": 125
  }
}
```

## Domain Types

### Audit Log

- `AuditLog`

  Audit log entry.

  - `id: string`

    Unique identifier for the audit log entry.

  - `action: string`

    The action that was performed.

  - `actor: AuditLogActor`

    The entity that performed the action.

    - `id: string`

      Unique identifier for the actor.

    - `name: string | null`

      Display name of the actor.

    - `type: AuditLogType`

      Type of actor.

      - `"user"`

      - `"api_key"`

  - `client_ip: string`

    Client IP address.

  - `created_at: string`

    When the action occurred.

  - `method: string`

    HTTP method of the request.

  - `path: string`

    Request path.

  - `status_code: number`

    HTTP status code of the response.

  - `user_agent: string`

    User agent string.

  - `target?: AuditLogTarget | null`

    The target resource of the action.

    - `id: string`

      Unique identifier for the target resource.

    - `type: string`

      Type of the target resource.

### Audit Log Actor

- `AuditLogActor`

  The entity that performed the action.

  - `id: string`

    Unique identifier for the actor.

  - `name: string | null`

    Display name of the actor.

  - `type: AuditLogType`

    Type of actor.

    - `"user"`

    - `"api_key"`

### Audit Log List

- `AuditLogList`

  - `items: Array<AuditLog>`

    - `id: string`

      Unique identifier for the audit log entry.

    - `action: string`

      The action that was performed.

    - `actor: AuditLogActor`

      The entity that performed the action.

      - `id: string`

        Unique identifier for the actor.

      - `name: string | null`

        Display name of the actor.

      - `type: AuditLogType`

        Type of actor.

        - `"user"`

        - `"api_key"`

    - `client_ip: string`

      Client IP address.

    - `created_at: string`

      When the action occurred.

    - `method: string`

      HTTP method of the request.

    - `path: string`

      Request path.

    - `status_code: number`

      HTTP status code of the response.

    - `user_agent: string`

      User agent string.

    - `target?: AuditLogTarget | null`

      The target resource of the action.

      - `id: string`

        Unique identifier for the target resource.

      - `type: string`

        Type of the target resource.

  - `pagination: Pagination`

    Pagination response details.

    - `next_cursor: string | null`

    - `previous_cursor: string | null`

    - `total_count: number`

### Audit Log Target

- `AuditLogTarget`

  The target resource of the action.

  - `id: string`

    Unique identifier for the target resource.

  - `type: string`

    Type of the target resource.

### Audit Log Type

- `AuditLogType = "user" | "api_key"`

  Type of actor.

  - `"user"`

  - `"api_key"`
