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

# Test mode

Build and test your integration with test keys, the Sandbox Network and test conversions.

Each workspace has live data and test data. The two are fully separate. A test key (`sk_test_...`) reads and writes test data only. A live key (`sk_live_...`) reads and writes live data only. Each object has the field `livemode`. It is `false` for test data.

## What is different in test mode

- **The Sandbox Network.** This network makes fake programs, conversions, clicks, payouts and deals. It needs no credentials. It works with a test key only. A live key gets [`network_unavailable`](https://docs.afffast.com/errors/network-unavailable.md). See [Connect Sandbox Network](https://docs.afffast.com/docs/connect/sandbox.md).
- **Test helpers.** `POST /v1/test/conversions` and `POST /v1/test/conversions/{id}/status` work with a test key only. A live key gets [`test_mode_only`](https://docs.afffast.com/errors/test-mode-only.md).
- **Webhooks.** A test endpoint can use `http`. A live endpoint must use `https`.
- **Limits and billing.** Test mode has no plan limits. The API never counts or bills test data.
- **Redirects.** Links work in test mode. The clicks are test data.
- **Real networks.** You can also connect a real network with a test key. The data stays in test mode.

A live ID does not work with a test key, and a test ID does not work with a live key. The API answers [`resource_not_found`](https://docs.afffast.com/errors/resource-not-found.md).

## Make a test conversion

You need a test connection. Use the Sandbox Network (see the [quickstart](https://docs.afffast.com/docs/quickstart.md)). You need the scope `conversions:write`.

```bash
curl -X POST https://api.afffast.com/v1/test/conversions \
  -H "Authorization: Bearer $AFFFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "connection": "conn_...",
    "amount": "100.00",
    "click_id": "..."
  }'
```

- `amount` and `commission` are decimal text. The default amount is `100.00`. The default commission is 10 % of the amount.
- `click_id` is the click ID of a click on a test link. The API puts it in the SubID slot of the network, like the redirector does. The conversion then gets `click_id`, `user_subids` and `click_context`. A click ID that no click has gives a conversion with no click context.

## Change the status

```bash
curl -X POST https://api.afffast.com/v1/test/conversions/conv_.../status \
  -H "Authorization: Bearer $AFFFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{ "status": "rejected" }'
```

The status is `pending`, `approved`, `rejected`, `paid` or `unknown`. The change goes through the same write as a sync. A new status writes the event `conversion.status_changed`, and your [webhook endpoints](https://docs.afffast.com/docs/webhooks.md) get it. Use this to test how your code handles a late rejection.

## Test the Sandbox scenarios

Set the field `scenario` of the Sandbox connection to test errors and large volumes:

- `default`: normal data.
- `high_volume`: 12 times more conversions and clicks.
- `failing_auth`: the credentials check fails.
- `rate_limited`: the first fetch in each window of 60 seconds fails with a rate limit error.

## Go live

1. Make a live key in the dashboard.
2. Connect your real networks with the live key.
3. Make new webhook endpoints, destinations and links with the live key. Test objects do not move to live mode.
4. Replace the test key in your code with the live key.
