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

# Access Logs

> Retrieve access history for policies

# Access Logs

Retrieve the complete access history for a policy.

## Endpoint

```http theme={null}
GET /api/access-logs/{policyId}
Authorization: Bearer {token}
```

## Parameters

| Parameter  | Type   | Required | Description       |
| ---------- | ------ | -------- | ----------------- |
| `policyId` | string | ✅        | Policy identifier |

## Response

### Success (200)

```json theme={null}
{
  "success": true,
  "logs": [
    {
      "timestamp": "2025-02-22T10:30:00Z",
      "txHash": "0xabc...",
      "success": true,
      "blockNumber": 12345678
    },
    {
      "timestamp": "2025-02-22T11:15:00Z",
      "txHash": "0xdef...",
      "success": false,
      "error": "Policy expired"
    }
  ]
}
```

## Log Entry Fields

| Field         | Type    | Description                  |
| ------------- | ------- | ---------------------------- |
| `timestamp`   | string  | ISO 8601 timestamp           |
| `txHash`      | string  | On-chain transaction hash    |
| `success`     | boolean | Whether access was granted   |
| `blockNumber` | number  | Block containing transaction |
| `error`       | string  | Error message (if failed)    |

## Example Usage

```typescript theme={null}
async function getAccessLogs(policyId: string) {
  const response = await fetch(`/api/access-logs/${policyId}`, {
    headers: {
      'Authorization': `Bearer ${token}`,
    },
  });

  const data = await response.json();
  return data.logs;
}

// Usage
const logs = await getAccessLogs('0xabc...');
const successful = logs.filter(l => l.success);
console.log(`Accessed ${successful.length} times`);
```

## Access Control

Only the **sender** or **recipient** of a policy can view its access logs.

```json theme={null}
{
  "error": "Unauthorized"
}
```

## Rate Limits

| Limit    | Value         |
| -------- | ------------- |
| Requests | 30 per minute |

## On-Chain Storage

Logs are stored on-chain via the `logAttempt` function. The API queries both:

1. **Blockchain events**: `VerificationAttempt` events
2. **Database**: Cached logs for performance

## Data Retention

| Plan       | Retention |
| ---------- | --------- |
| Free       | 30 days   |
| Pro        | 90 days   |
| Enterprise | Unlimited |
