Skip to main content

Idempotent Requests

Our /send endpoint supports idempotency for safely retrying requests without accidentally sending the same email twice. This is useful to guarantee that an email is not sent to the same recipient multiple times, e.g. through a network error, or a bug in your application logic.

To do this, when sending an email, you generate and add a unique Idempotency-Key string to the headers of the send request. You can then safely repeat the request without risk of sending the same email twice.

Typically you would use a UUID to do this (we suggest using V4 UUIDs), although you can use any unique string of your choice, with enough entropy to avoid a collision.

Implementation Details

MailPace stores the response to all successful requests, and returns that response on all subsequent requests with the same Idempotency Key and Server Token, regardless of request body.

There are some additional considerations:

  • Each key has a maximum length of 255 characters.
  • Keys are expired at MailPace after 24 hours
  • Each key is unique to the API Token, reusing the same Idempotency Key with a different Domain or API Token will result in the email being sent

We save results only after the email is queued for sending. If incoming parameters fail validation, or the request conflicts with another request that’s executing concurrently, we don’t save the idempotent result, and you can safely retry these requests.

Examples

Here are some examples in various languages.

curl "https://app.mailpace.com/api/v1/send" \
-X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "MailPace-Server-Token: API_TOKEN_GOES_HERE" \
-H "Idempotency-Key: UNIQUE_STRING_EG_UUIDV4_GOES_HERE" \
-d '{
"from": "example@domain.com",
"to": "person@somewhere.com",
"subject": "Hello from MailPace.com",
"textbody": "Hello"
}'