# Idempotency

> Every POST needs an Idempotency-Key header. WP Waterfall stores the first response for 24 hours and replays it for a retry with the same key and body.

Source: https://docs.wpwaterfall.com/developers/idempotency

Send an `Idempotency-Key` header on every POST. A POST without one answers `422`. WP Waterfall stores the first response for 24 hours and replays it when the same key arrives with the same body.

```bash
curl -s -X POST https://api.wpwaterfall.com/v1/companies/me/invitations \
  -H "Authorization: Bearer wpw_live_YOUR_SECRET" \
  -H "Idempotency-Key: 8f2c-retry-1" \
  -H "Content-Type: application/json" \
  -d '{"email":"teammate@example.com","role":"developer"}'
```

A second POST with the same key and body returns the first response, and no second invitation is created.

## What if I reuse a key?

- The same key with a different body answers `422`.
- The same key while the first request is still running answers `409` with `Retry-After: 2`. Wait, then repeat the request to get its answer.

Use a new key for each new operation. UUIDs work well. If your network dropped during a POST, send the same request with the same key: you get the stored response if it went through, or a fresh result if it did not. GET, PATCH, PUT, and DELETE need no key.

PUT and PATCH accept the header too. When such a call starts a job, a retry with the same key, path, and body within 24 hours returns that job. A key used on another environment, on another path, or with another body starts a new job, and so does the same request after 24 hours.
