Idempotency: retry a change safely
Every change carries a request_id you make up, so sending it again answers the first answer and nothing happens twice.
Last updated 4 min read
A network can drop the answer to a change after Current has made it. So every change takes a request_id: a uuid your tool makes up for that change. Send the same one again and Current answers the first answer again, with replayed set to true, and nothing happens twice. Current keeps each request_id for 24 hours.
REQUEST_ID=$(uuidgen) # a new id for this change; send the same one again only to retry it
curl -sS --fail-with-body --retry 2 -X POST "https://api.current.day/v1/tickets/6f1d2e8b-4c10-4a7e-9a52-0b8f2c5e3c1d/notes" \
-H "Authorization: Bearer $CURRENT_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $REQUEST_ID" \
-d @- <<EOF
{"request_id":"$REQUEST_ID","body":"Called the customer back."}
EOF
# a retry answers the first answer again, with "replayed": trueThe rules
- Send request_id in the body, or the same uuid in an Idempotency-Key header, or both with the same value.
- Make a new request_id for each new change. Reuse one only to retry that same change.
- A change without one is refused: 400 bad_request, reason request_id_missing.
- The same request_id with different details is refused: 409 conflict, reason request_id_reused.
- A retry that arrives while the first is still running is refused: 409 conflict, reason in_progress. Wait a moment, then send it again.
- Reads take no request_id.
Is it safe to retry a change in the Current API?
Yes, with the same request_id. Current answers the first answer again with replayed set to true and never makes the change twice. Each request_id is kept for 24 hours. See the current-api-idempotency article. The Current API is not open yet.
