# Idempotency

> Send Idempotency-Key on a POST and retry without fear of duplicating a payout, a link or a conversion.

[Sandbox · coming soon]

A network that drops in the middle of a call leaves you not knowing whether the operation happened. With `Idempotency-Key` you can retry the same call and receive the same response, without creating a second payout.

> **Sandbox only, for now**
>
> Production ignores `Idempotency-Key` today. Until it arrives, on a 5xx or a timeout of `POST /v1/transfer` in production, confirm in the customer portal whether the withdrawal was created before retrying.

## How it works

1. Generate a unique key per operation (a UUID v4) and send it in the `Idempotency-Key` header of any authenticated `POST`.
2. If the call drops, retry with **the same key and the same body**.
3. zulu keeps the successful response for 24 hours per workspace. An identical retry receives the same response, with the `Idempotent-Replayed: true` header.

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Idempotency-Key: 7f9c2ba4-e88f-4c6e-9d43-6a8b8f0f5d21" \
  -H "Content-Type: application/json" \
  -d @payout.json
```

## Rules

- The key is up to 255 characters and serves one operation with one body.
- The same key with another body or another operation answers `422`: use a new key for every distinct operation.
- If the first call is still running, the retry answers `409`: wait a few seconds and try again.
- Only 2xx responses are kept. A validation or business error does not consume the key: fix it and retry with the same one.

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 409 | `ResourceConflictApiError` | `idempotency key "%s" is still being processed` | Another call with the same `Idempotency-Key` is still running. Retry in a few seconds to receive its response. |
| 422 | `UnprocessableEntityApiError` | `idempotency key "%s" was used with a different request` | The `Idempotency-Key` was already used in the last 24 hours with a different body or operation. Use a new key for every distinct operation. |
