> The index of all pages is at https://docs.afffast.com/llms.txt.

# Audit log

See who changed what and when. Read the history of a conversion, a program, a deal, a payout or a connection, and the audit log of your workspace, with the API.

The audit log is a record of the important changes of your data. It shows what changed, when it changed, who changed it and where the change came from. Each detail page in the dashboard shows the history of its object as a timeline. The API gives the same data.

## What an entry is

One entry is one change of one object. When a network sync changes the status and the commission of a conversion in one write, the log has one entry with both changes.

| Field          | Meaning                                                                                                           |
| -------------- | ----------------------------------------------------------------------------------------------------------------- |
| `object_type`  | The type of the object, for example `conversion`.                                                                 |
| `object_id`    | The ID of the object.                                                                                             |
| `action`       | `created`, `updated`, `deleted` or `restored`.                                                                    |
| `changes`      | A list of `{field, from, to}`. Only the fields of the list below make an entry.                                   |
| `reason`       | The reason of the change, if there is one. For a conversion it is the reason of the status.                       |
| `actor`        | Who made the change: `type`, `id` and `name`.                                                                     |
| `source`       | Where the change came from: `sync`, `import`, `postback`, `test_helper`, `dashboard`, `api`, `oauth` or `system`. |
| `detected_at`  | The time when AffFast saw or made the change. It is always set.                                                   |
| `effective_at` | The time that the network gives for the change, for example the time of a decision. It can be `null`.             |

The actor `name` is the name at the time of the change. A later rename does not change it.

### The actor

- `sync`: a sync of a connection. The `id` is the connection and the `name` is its label.
- `user`: a member of your workspace.
- `api_key`: an API key.
- `system`: AffFast itself, for example the job that approves old pending conversions.

### Two times

`detected_at` is when AffFast saw the change. A network can decide a sale days before the next sync reads it. The network then gives the time of its decision, and AffFast saves it as `effective_at`. The dashboard timeline shows `effective_at` when it is set, and `detected_at` when it is not.

## Which fields make an entry

| Object                            | Fields                                                                                                |
| --------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Conversion                        | `status` (with the reason), `order_amount` and `commission`. Amounts are in the money of the network. |
| Program                           | `status`, `commission` (the terms) and `cookie_days`.                                                 |
| Deal                              | `status` (`active` or `removed`), `code`, `starts_at`, `ends_at` and `terms`.                         |
| Payout                            | `status`, `amount` and `paid_at`.                                                                     |
| Connection                        | `status`, `label`, `timezone`, and a change of the credentials.                                       |
| Link                              | `destination`, `program_id`, `site_id` and `active`.                                                  |
| Site                              | `name` and `domain`.                                                                                  |
| Brand                             | `name` and `domain`.                                                                                  |
| Tag                               | `name` and `color`.                                                                                   |
| Destination, notification channel | `label`, `status`, `config`, and a change of the credentials.                                         |
| Webhook endpoint                  | `url`, `description`, `events`, `status`, and a change of the signing secret.                         |
| Log drain                         | `label`, `status`, `config`, `sources`, and a change of the credentials.                              |
| API key                           | `name`, `scopes`, `expires_at` and `revoked_at`. The secret is never in the log.                      |
| Workspace                         | `name`, `default_currency`, `timezone` and `locale`.                                                  |
| Member                            | `role`.                                                                                               |

A create makes the entry `created`, with the first values. A delete and a restore from the [Trash](https://docs.afffast.com/docs/trash.md) make the entries `deleted` and `restored`. The automatic rotation of the token of a connection makes an entry of the actor `system`.

A change that an AI app makes through the [MCP server](https://docs.afffast.com/docs/mcp.md) has the source `oauth` and the user who connected the app as the actor. A new or a revoked connection of an app is an entry with the object type `oauth_grant`.

Read the entries of these objects with `GET /v1/audit_log?object_id=<id>`. The detail pages of the dashboard show them as a history.

A change of any other field, for example the time of the last sync, makes no entry.

An amount is an object with `amount` (a decimal text) and `currency`:

```json
{
  "field": "commission",
  "from": { "amount": "80.0000", "currency": "DKK" },
  "to": { "amount": "64.0000", "currency": "DKK" }
}
```

The log never has a secret. A change of a credential or of a signing secret shows as `{"field": "credentials", "from": null, "to": "changed"}`.

## Read the history of one object

Send `GET /v1/conversions/{id}/history`. The same endpoint exists for programs, deals, payouts and connections. The list is oldest first. It uses [pagination](https://docs.afffast.com/docs/pagination.md): `starting_after` goes to newer entries and `ending_before` goes to older entries.

```bash
curl https://api.example.com/v1/conversions/conv_0Yx3kqW7sRzL1nH8aBcD4e/history \
  -H "Authorization: Bearer sk_test_..."
```

You can also get the newest 100 entries with the object. Add `expand[]=history` to the request of the object:

```bash
curl "https://api.example.com/v1/conversions/conv_0Yx3kqW7sRzL1nH8aBcD4e?expand[]=history" \
  -H "Authorization: Bearer sk_test_..."
```

## Read the audit log of the workspace

Send `GET /v1/audit_log`. The list is newest first. Use these filters:

- `object_type` and `object_id`
- `actor_type` and `source`
- `date[gte]` and `date[lte]`, for the time of `detected_at`

The scope `audit_log:read` is needed for the audit log, the history endpoints and `expand[]=history`. The scope `read_only` includes it. Each member of the workspace can read the history in the dashboard.

Test mode and live mode have separate logs.

## How long the log keeps an entry

The plan sets how far back you can read the log: 3 months on Starter, 12 months on Pro and 24 months on Business (`audit_log_months` in `GET /v1/workspace`). The API and the dashboard show no older entry. This applies to `GET /v1/audit_log`, the history endpoints and `expand[]=history`. A `date[gte]` before the limit is not an error: the list starts at the limit. Test mode has no limit. We keep an entry for 24 months, the longest plan time, then we delete it. A bigger plan shows the older entries that we still keep. The entry stays after the object is deleted.

The audit log has no webhook events. The existing [events](https://docs.afffast.com/docs/webhooks.md) stay as they are.
