# Idempotency

Every route that changes data takes an optional `Idempotency-Key` header. Send the same key when you retry, and Inboxjot runs the request only once.

## Rules

A key is 1 to 256 printable ASCII characters. It belongs to your workspace and lasts 24 hours.

Inboxjot compares the method, the path and the body. A retry with the same request replays the stored response with `Idempotent-Replayed: true`.

The same key with a different request answers `422` with `invalid_idempotent_request`. A request that is still running answers `409` with `concurrent_idempotent_requests` and `Retry-After: 1`.

Only a 2xx response is stored. After any other response you can fix the request and retry with the same key.

A request that stops without a response, such as one cut off by a timeout, releases its key after 60 seconds. A retry then runs the request again.

## Request

cURL:

```bash
curl -X POST https://api.inboxjot.com/v1/emails \
  -H "Authorization: Bearer $INBOXJOT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-4821-receipt" \
  -d '{
    "from": "Acme <hello@acme.dev>",
    "to": "riti@example.com",
    "subject": "Your receipt from Acme",
    "html": "<p>Thanks for your order.</p>"
  }'
```

## Responses

| Status | Description |
| --- | --- |
| 422 | This idempotency key was already used with a different request. |

422:

```json
{
  "name": "invalid_idempotent_request",
  "status": 422,
  "message": "This idempotency key was already used with a different request",
  "errors": [],
  "request_id": "5f0c6a2e-8d1b-4c7a-9e3f-2b6d4a1c8e90"
}
```
