Core concepts
Idempotency
Retry creates and refunds safely. The same Idempotency-Key always gets the same response, and the action happens once.
Networks fail. If a request to create something times out, you can't tell whether Cartirra received it. An idempotency key makes the retry safe: Cartirra runs the request once and returns the first response to every retry.
curl -X POST https://api.cartirra.com/v1/orders/ord_0193a1b2c3d47e5f8a9b0c1d2e3f4a5b/refunds \
-H "Authorization: Bearer $CARTIRRA_SECRET_KEY" \
-H "Idempotency-Key: 6f1c2b7e-1d5a-4c55-9a0e-7d6f3f1b9a10" \
-H "Content-Type: application/json" \
-d '{ "amount": { "amount": "2000.00", "currency": "NGN" }, "reason": "Missing item" }'
Which endpoints take one
| Endpoint | Idempotency-Key |
|---|---|
POST /v1/orders/{id}/refunds | Required. Refunds move money. |
POST /v1/checkout-sessions | Recommended |
POST /v1/promotions | Recommended |
POST /v1/gift-cards | Recommended |
Each endpoint's reference page says whether it takes a key. Reads (GET) don't need one.
Rules
- A key is 8–255 characters of
A–Z a–z 0–9 . _ : -. A UUID v4 is a good choice. - Make one key per action, not per attempt: generate it before the first try and reuse it for every retry of that action.
- Keys are kept for 24 hours and belong to your business and mode.
- A replay returns the first status and body, with the header
Idempotency-Replayed: true.
What you may see
| Status | Code | Meaning |
|---|---|---|
| 400 | idempotency_key_required | This endpoint needs a key and none was sent |
| 400 | validation_failed | The key isn't 8–255 allowed characters |
| 409 | idempotency_request_in_progress | The first request with this key is still running. Wait a moment and retry |
| 422 | idempotency_key_reused | The key was already used for a different request. Use a new key for a new action |
Errors are remembered too: if the first request failed validation, the retry gets the same error. A 5xx is not remembered, so retrying the same key after a server error runs the request again, safely.