Idempotency-Key
header with any POST, and you can retry it without doing the work twice.
How it works
- The key is any unique string of up to 255 characters. A UUID works well.
- Hammock saves the status and body of the first response for a key, and returns the same response
to every retry with that key. That includes
500errors. - Keys are kept for 24 hours. After that, a reused key is treated as a new request.
- A response is saved once the request starts running. A request that fails validation, or collides with another still in progress, isn’t saved and can be retried.
Mismatches
A key belongs to one request. Reusing it with a different endpoint or different parameters returns anidempotency_error with the code idempotency_key_reused, so a bug that recycles keys
can’t silently return the wrong response.
Two requests with the same key at the same time don’t both run. The second returns 409 with
idempotency_request_in_progress.
Where it applies
Send a key with everyPOST: creating, updating, voiding and rolling a secret. GET and
DELETE are idempotent already and ignore the header.
That includes employer links and enrollment links. A retry returns the same single-use URL, which is
what you want: you only retry when the first response never reached you, so the URL is still
unused.
The sandbox test helpers are the one exception. They don’t take the header.
External IDs are a second guard
external_id protects you beyond the 24 hours a key lasts. Reporting a payroll whose
external_id already exists returns external_id_taken, however long ago the first report was.
If you get that error after a timeout, retrieve the payroll with
GET /payrolls?employer=...&external_id=... to see what was recorded.