# Audit Logs

## Get Audit Log

`client.AuditLogs.Get(ctx, auditLogID) (*AuditLog, error)`

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

Get an Audit Log entry

### Parameters

- `auditLogID string`

### Returns

- `type AuditLog struct{…}`

  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`

      Display name of the actor.

    - `Type AuditLogType`

      Type of actor.

      - `const AuditLogTypeUser AuditLogType = "user"`

      - `const AuditLogTypeAPIKey AuditLogType = "api_key"`

  - `ClientIP string`

    Client IP address.

  - `CreatedAt Time`

    When the action occurred.

  - `Method string`

    HTTP method of the request.

  - `Path string`

    Request path.

  - `StatusCode int64`

    HTTP status code of the response.

  - `UserAgent string`

    User agent string.

  - `Target AuditLogTarget`

    The target resource of the action.

    - `ID string`

      Unique identifier for the target resource.

    - `Type string`

      Type of the target resource.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/option"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  auditLog, err := client.AuditLogs.Get(context.TODO(), "audit_log_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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(ctx, query) (*Cursor[AuditLog], error)`

**get** `/v1/audit_logs`

List Audit Log entries for an organization

### Parameters

- `query AuditLogListParams`

  - `Cursor param.Field[string]`

    Pagination cursor returned by a previous request

  - `Limit param.Field[int64]`

    Maximum number of items to return

### Returns

- `type AuditLog struct{…}`

  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`

      Display name of the actor.

    - `Type AuditLogType`

      Type of actor.

      - `const AuditLogTypeUser AuditLogType = "user"`

      - `const AuditLogTypeAPIKey AuditLogType = "api_key"`

  - `ClientIP string`

    Client IP address.

  - `CreatedAt Time`

    When the action occurred.

  - `Method string`

    HTTP method of the request.

  - `Path string`

    Request path.

  - `StatusCode int64`

    HTTP status code of the response.

  - `UserAgent string`

    User agent string.

  - `Target AuditLogTarget`

    The target resource of the action.

    - `ID string`

      Unique identifier for the target resource.

    - `Type string`

      Type of the target resource.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/nirvana-labs/nirvana-go"
  "github.com/nirvana-labs/nirvana-go/audit_logs"
  "github.com/nirvana-labs/nirvana-go/option"
)

func main() {
  client := nirvana.NewClient(
    option.WithAPIKey("My API Key"),
  )
  page, err := client.AuditLogs.List(context.TODO(), audit_logs.AuditLogListParams{

  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
```

#### 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

- `type AuditLog struct{…}`

  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`

      Display name of the actor.

    - `Type AuditLogType`

      Type of actor.

      - `const AuditLogTypeUser AuditLogType = "user"`

      - `const AuditLogTypeAPIKey AuditLogType = "api_key"`

  - `ClientIP string`

    Client IP address.

  - `CreatedAt Time`

    When the action occurred.

  - `Method string`

    HTTP method of the request.

  - `Path string`

    Request path.

  - `StatusCode int64`

    HTTP status code of the response.

  - `UserAgent string`

    User agent string.

  - `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 Actor

- `type AuditLogActor struct{…}`

  The entity that performed the action.

  - `ID string`

    Unique identifier for the actor.

  - `Name string`

    Display name of the actor.

  - `Type AuditLogType`

    Type of actor.

    - `const AuditLogTypeUser AuditLogType = "user"`

    - `const AuditLogTypeAPIKey AuditLogType = "api_key"`

### Audit Log List

- `type AuditLogList struct{…}`

  - `Items []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`

        Display name of the actor.

      - `Type AuditLogType`

        Type of actor.

        - `const AuditLogTypeUser AuditLogType = "user"`

        - `const AuditLogTypeAPIKey AuditLogType = "api_key"`

    - `ClientIP string`

      Client IP address.

    - `CreatedAt Time`

      When the action occurred.

    - `Method string`

      HTTP method of the request.

    - `Path string`

      Request path.

    - `StatusCode int64`

      HTTP status code of the response.

    - `UserAgent string`

      User agent string.

    - `Target AuditLogTarget`

      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.

    - `NextCursor string`

    - `PreviousCursor string`

    - `TotalCount int64`

### Audit Log Target

- `type AuditLogTarget struct{…}`

  The target resource of the action.

  - `ID string`

    Unique identifier for the target resource.

  - `Type string`

    Type of the target resource.

### Audit Log Type

- `type AuditLogType string`

  Type of actor.

  - `const AuditLogTypeUser AuditLogType = "user"`

  - `const AuditLogTypeAPIKey AuditLogType = "api_key"`
