Idempotency for batch emails
When sending batch transactional emails, duplicate requests can cause the same emails to be sent multiple times. Use idempotency to ensure that identical requests are processed only once, preventing duplicate deliveries to recipients.
How idempotency works
To enable idempotency, include an idempotencyKey header in your request. The API processes a request only once per unique key, ignoring subsequent requests with the same key within the time-to-live (TTL) period.
The idempotencyKey must be a UUID (Universally Unique Identifier). Generate a unique key for each distinct batch request. If you need to retry the exact same request, reuse the same key.
Example request
Here’s a complete request using the idempotency key:
Time-to-live and error handling
The TTL for idempotencyKey is 30 minutes. After the TTL expires, you can reuse the same key for a new request.
If you submit a request with an idempotencyKey that was used within the last 30 minutes, the API returns a duplicate_parameter error and does not process the request. This prevents duplicate emails from being sent.
Using idempotency with message versions
Idempotency works with messageVersions for sending personalized batches. The same idempotency key applies to the entire batch, regardless of how many versions are included.
When using messageVersions with an idempotency key, the API returns one message ID per version. In the example above, you’ll receive two message IDs in the response—one for each message version.