What is idempotency?
Idempotency ensures that retrying a request (due to network issues, timeouts, etc.) will not result in duplicate emails.Usage
- Header:
Idempotency-Key - Type: Any unique string (UUID v4 recommended)
- Scope: Each unique key + request body is valid for 24 hours
How it works
- If you send the same request with the same
Idempotency-Keywithin 24 hours, you’ll get the same response and no duplicate email is sent. - If you send a different request body with the same key, you’ll get a
422error.
Examples
Send an email
Retry with the same key and body
If you retry the exact same request, you will receive a202 Accepted with the same message_id and no duplicate email will be sent.
Conflict with same key, different body
422 Unprocessable Entity response with:
SMTP
If you need idempotency but are using the SMTP relay, you can simply add the header to the SMTP request and we’ll handle the request similar to the API.Example
You can use the following example fornodemailer:
Recommendations
- Always set
Idempotency-Keywhen retries are possible. - Generate a new key for each unique email.
- Store the key if you need to retry the same request.
- Do not reuse keys for different emails.
Idempotency-Key header to your /send requests to prevent duplicate emails when retrying. Use a unique key per email. Identical key + body will be safe to retry; identical key + different body results in an error.