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

# Idempotency

> Retry End Close API writes safely with the Idempotency-Key header: which endpoints accept it, how replays work, and what 409 and 422 mean.

The `Idempotency-Key` header lets you retry a write without applying it twice. Send a unique key with the request; if you send the same request with the same key again, End Close returns the first response instead of repeating the write.

Use it whenever a write might have landed but you didn't get the answer: a timeout, a dropped connection, or a worker that restarted mid-request.

## Endpoints that accept Idempotency-Key

| Endpoint | |
| - | - |
| `POST /records` | Create a record |
| `PATCH /records/{id}` | Update a record |
| `DELETE /records/{id}` | Delete a record |
| `POST /records/bulk` | Bulk create records ([works differently](#bulk-record-uploads)) |
| `POST /reconciliations/{reconciliation_id}/records/{record_id}/mark_overdue` | Mark a record as overdue |
| `POST /reconciliations/{id}/run` | Run a reconciliation |
| `POST /reconciliation_rules` | Create a rule |
| `PATCH /reconciliation_rules/{id}` | Update a rule |
| `DELETE /reconciliation_rules/{id}` | Delete a rule |
| `POST /reconciliation_matches` | Create a match |
| `DELETE /reconciliation_matches/{id}` | Delete a match |
| `POST /reconciliation_exceptions` | Create an exception |
| `PATCH /reconciliation_exceptions/{id}` | Update an exception |
| `DELETE /reconciliation_exceptions/{id}` | Delete an exception |
| `PUT /reconciliation_exceptions/{id}/findings` | Write findings for an exception's lines |
| `PUT /reconciliations/{reconciliation_id}/data_streams/{data_stream_id}/findings` | Write findings for a data stream's lines |

Other endpoints ignore the header.

## Send a key

Generate a unique value per logical write, such as a UUID, and reuse it only when retrying that same write. Keys can be up to 255 characters.

```bash cURL theme={"dark"}
curl -X POST https://api.endclose.com/v1/reconciliation_matches \
  -H "X-API-Key: $ENDCLOSE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 3f0c9a4e-6b1d-4c8e-9f27-5a2b7d1e0c64" \
  -d '{
    "reconciliation_id": "019a4e10-5b2d-7c80-b3f4-2a9d8e6c7b15",
    "record_ids": [
      "019a4f2e-8c1b-7d35-9e2a-4b6c1f0d3e57",
      "019a4f2f-1d44-7a02-8b6e-93c0a5f7d218"
    ]
  }'
```

## What happens when you reuse a key

End Close compares the retry with the first request using the method, the path, the query string and the JSON body. Key order inside the JSON doesn't matter.

| Situation | Response |
| - | - |
| Same key, same request, first request finished | The first response again, with the same status and body, plus the header `Idempotent-Replayed: true`. Nothing is written. |
| Same key, same request, first request still running | `409 Conflict`. Wait and retry with the same key. |
| Same key, different request | `422 Unprocessable Entity`: the key was already used for a different request. Use a new key. |
| No key | The request runs normally, with no protection against duplicates. |

Only successful responses are stored. If the first request fails or is refused, the key is released, so you can fix the request and send it again with the same key. If the first request never finished, for example because the server handling it stopped, a retry with the same key runs the request once 10 minutes have passed.

Keys belong to one environment and are kept for 7 days. A Sandbox key and a Production key with the same value don't interact.

## Bulk record uploads

`POST /records/bulk` handles the header differently. If a bulk request with that key already exists in your environment, the API returns the existing bulk request with `202 Accepted` instead of creating a new one. The request body isn't compared with the original.

## Create a record with your own ID

`POST /records` has a second option. Send your own `id` (a UUID; uuidv7 recommended) in the body. If a record with that `id` already exists in your environment, the API returns it with `201 Created` instead of creating a duplicate, and the first write wins. An `id` already used in another environment returns `409 Conflict`.

## FAQ

> [accordion] How do I know a response was replayed?
>
> A replayed response has the header `Idempotent-Replayed: true`. Its status and body match the first response.

> [accordion] Can I reuse a key after a 422 validation error?
>
> Yes. A failed or refused request doesn't keep its key, so you can correct the request and send it with the same key.

> [accordion] Do GET requests need an idempotency key?
>
> No. Reads don't change data, and the API ignores the header on them.

## Related

> [card] [Errors](https://endclose.com/docs/api-reference/errors.md)
>
> Status codes and retry guidance.

> [card] [Bulk create records](https://endclose.com/docs/api-reference/bulk-create-records.md)
>
> Upload up to 1,000 records in one request.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.