> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ozura.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Querying Audit Logs

# Querying Audit Logs

Filter and search audit logs for compliance and debugging.

## Basic Query

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

## Filtering

### By Event Type

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?event_type=TOKEN_CREATION" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

### By Date Range

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?start_date=2024-01-01&end_date=2024-01-31" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

### By User

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?user_id=usr_abc123" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

### By Application

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?app_id=app_xyz789" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

### By Resource

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?resource_id=tok_abc123" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

## Query Parameters

| Parameter | Type | Description |
| - | - | - |
| `event_type` | string | Filter by event type |
| `action` | string | Filter by action |
| `resource_type` | string | Filter by resource type |
| `resource_id` | string | Filter by specific resource |
| `user_id` | string | Filter by user |
| `app_id` | string | Filter by application |
| `start_date` | string | Start of date range (ISO 8601) |
| `end_date` | string | End of date range (ISO 8601) |
| `ip_address` | string | Filter by IP address |
| `page` | number | Page number (default: 1) |
| `limit` | number | Items per page (default: 50, max: 100) |

## Combined Filters

Multiple filters can be combined:

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?\
event_type=TOKEN_CREATION&\
start_date=2024-01-01&\
end_date=2024-01-31&\
limit=100" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."
```

## Pagination

```json theme={null}
{
  "success": true,
  "data": {
    "logs": [...],
    "pagination": {
      "page": 1,
      "limit": 50,
      "total": 1250,
      "pages": 25
    }
  }
}
```

### Paginate Through Results

```javascript theme={null}
async function getAllLogs() {
  let allLogs = [];
  let page = 1;
  let hasMore = true;

  while (hasMore) {
    const response = await fetch(`/audit-logs?page=${page}&limit=100`, {
      headers: { 'Authorization': `Bearer ${token}` }
    });
    const data = await response.json();

    allLogs = allLogs.concat(data.data.logs);

    if (page >= data.data.pagination.pages) {
      hasMore = false;
    } else {
      page++;
    }
  }

  return allLogs;
}
```

## Response Format

```json theme={null}
{
  "success": true,
  "data": {
    "logs": [
      {
        "id": "log_abc123",
        "event_type": "TOKEN_CREATION",
        "action": "TOKENIZE",
        "resource_type": "TOKEN",
        "resource_id": "tok_xyz789",
        "user_id": "usr_def456",
        "app_id": "app_ghi789",
        "timestamp": "2024-01-15T10:30:00Z",
        "ip_address": "203.0.113.50",
        "details": {
          "token_type": "card",
          "masked_number": "411111******1111",
          "fingerprint": "fp_abc123"
        }
      }
    ],
    "pagination": {
      "page": 1,
      "limit": 50,
      "total": 1250,
      "pages": 25
    }
  }
}
```

## Common Queries

### Recent Token Activity

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?\
resource_type=TOKEN&\
start_date=$(date -v-7d +%Y-%m-%d)&\
limit=100" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Failed Authentication

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?\
event_type=LOGIN_FAILED&\
limit=50" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Detokenization Audit

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?\
event_type=DETOKENIZATION&\
start_date=2024-01-01&\
end_date=2024-01-31" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Activity by IP Address

```bash theme={null}
curl -X GET "$YOUR_VAULT_URL/audit-logs?\
ip_address=203.0.113.50&\
limit=100" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

## Export Options

### JSON Export

Default format, suitable for programmatic processing.

### CSV Export (Coming Soon)

For spreadsheet analysis and reporting.

## Best Practices

### 1. Regular Reviews

Schedule periodic audit log reviews:

* Daily: Failed authentication attempts
* Weekly: Detokenization activity
* Monthly: Full compliance review

### 2. Set Up Alerts

Monitor for suspicious patterns:

* Unusual detokenization volume
* Access from new IP addresses
* Failed authentication spikes

### 3. Retention Planning

* Default retention: 2 years
* Download older logs if needed beyond retention
* Consider compliance requirements (PCI, SOC 2)

## Next Steps

* [Event Types](events.md) - All event types reference
* [Error Handling](../errors/README.md) - Understanding errors in logs


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.