Idempotency
Overview
The Prolifi API supports idempotency for all mutating requests (POST, PATCH, PUT, DELETE). By including an Idempotency-Key header, you ensure that the same operation is not executed more than once, even if you retry the request due to a network failure or timeout.
How it works
- Include an
Idempotency-Keyheader with a unique value (up to 255 characters). - Prolifi processes the request normally and caches the response.
- If you send the same
Idempotency-Keyagain, Prolifi returns the cached response instead of re-executing the operation. - Cached responses include an
Idempotent-Replayed: trueheader so you know the response is a replay.
Request example
If the request times out and you retry with the same Idempotency-Key, you will either receive the original response (if it was processed) or the request will be executed for the first time.
Key guidelines
If the Idempotency-Key header exceeds 255 characters, the request is rejected with a 400 error before any processing occurs.
Generating idempotency keys
Use a deterministic key derived from the operation being performed. Good strategies:
- UUID v4 for one-off operations:
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000 - Action-based for business operations:
Idempotency-Key: create-sub-cust123-plan456 - Hash-based for event reporting:
Idempotency-Key: sha256(customer_id + event_name + timestamp)
Avoid reusing idempotency keys across different operations, as this will return the cached response from the first operation.
Replayed responses
When Prolifi returns a cached response, the Idempotent-Replayed header is set:
Your application can check for this header to distinguish between first-time and replayed responses, though in most cases the distinction is not important.