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

# Audit

> Log and query tamper-evident audit entries

## Log

<Warning>
  Go SDK `v0.1.10` cannot create an audit entry through
  `client.Audit.Log`: its `LogAuditParams` omits the API-required `agentDid` and
  `principalId` fields. Use the REST endpoint or CLI for writes.
  List and get remain available, but `AuditEntry` omits `DeveloperID`; the SDK
  advertises `Since`, `Until`, `Page`, and `PageSize` filters that the API ignores;
  and list helpers do not URL-encode reserved characters in filter values. Use only
  `AgentID`, `GrantID`, `PrincipalID`, and `Action`, and issue a URL-encoded REST
  request when the missing field or reserved characters matter.
  Repository source on `main` corrects these gaps with regression coverage, but no
  corrected Go module tag has been published. This warning still applies to `v0.1.10`.
</Warning>

```bash REST workaround theme={null}
curl -X POST https://api.grantex.dev/v1/audit/log \
  -H "Authorization: Bearer $GRANTEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agentId": "ag_01HXYZ...",
    "agentDid": "did:grantex:ag_01HXYZ...",
    "grantId": "grnt_01HXYZ...",
    "principalId": "user_123",
    "action": "email:read",
    "status": "success",
    "metadata": {"messageId": "msg-123"}
  }'
```

## List

```go theme={null}
result, err := client.Audit.List(ctx, &grantex.ListAuditParams{
    AgentID:     "agent-id",
    PrincipalID: "user-123",
    Action:      "email:read",
})
for _, e := range result.Entries {
    fmt.Printf("[%s] %s: %s\n", e.Timestamp, e.Action, e.Status)
}
```

Pass `nil` for no filters.

## Get

```go theme={null}
entry, err := client.Audit.Get(ctx, "entry-id")
```

## Types

### `AuditEntry`

<Note>
  This table describes repository source on `main`. Public `v0.1.10` omits
  `DeveloperID`; use the REST response when that field is required.
</Note>

| Field         | Type                     | Description                                                                    |
| ------------- | ------------------------ | ------------------------------------------------------------------------------ |
| `EntryID`     | `string`                 | Entry ID                                                                       |
| `AgentID`     | `string`                 | Agent ID                                                                       |
| `AgentDID`    | `string`                 | Agent DID                                                                      |
| `GrantID`     | `string`                 | Grant ID                                                                       |
| `PrincipalID` | `string`                 | User ID                                                                        |
| `DeveloperID` | `string`                 | Owner developer ID (repository source on `main`; absent from public `v0.1.10`) |
| `Action`      | `string`                 | Action performed                                                               |
| `Metadata`    | `map[string]interface{}` | Custom metadata                                                                |
| `Hash`        | `string`                 | Entry hash (chain integrity)                                                   |
| `PrevHash`    | `*string`                | Previous entry hash                                                            |
| `Timestamp`   | `string`                 | ISO 8601 timestamp                                                             |
| `Status`      | `string`                 | `"success"`, `"failure"`, `"blocked"`                                          |
