Transactional Emails via API: Idempotency and Signed Webhooks
By Equipo de Replifier · ·Email
The business problem
An online store wants to send order confirmations automatically from its own system: the moment a payment is processed, the customer receives an email with their order summary. The challenge is not the send itself — it is reliability. When there are network hiccups or server failures, the system may retry the same request more than once. Without a protection mechanism, the customer receives the same email two or three times, which is confusing and looks unprofessional.
The team also wants to know when an email was delivered or failed, without having to check a dashboard manually.
How Replifier solves it
Replifier requires an Idempotency-Key header on every transactional send. You choose the value — your order ID, your transaction UUID — and Replifier guarantees that identifier is processed only once. If the system retries with the same key and the same body, Replifier returns the same result without creating a second send. The customer does not receive duplicates, even if the server failed and retried five times.
For delivery notifications, Replifier signs every webhook event with HMAC-SHA256. Your server can verify the signature before processing the event, confirming the notification actually came from Replifier and not from an external request.
Step by step
Before you start: you need a brand configured in Replifier with at least one active email provider.
-
In the Replifier dashboard, create an API key and assign it only the
messages.sendscope. Using the minimum scope limits the impact if the key is ever leaked. Store it in a server-side environment variable; never in source code. -
From your system, build the POST request to the send endpoint. Include the
Idempotency-Keyheader with your order ID:
curl -X POST "https://api.replifier.com/v1/brands/brd_your_brand/messages" \
-H "Authorization: Bearer <your_api_key>" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-98765" \
-d '{
"to": "customer@example.com",
"template": "confirm-order",
"variables": {
"order_number": "98765",
"total": "USD 125.00"
}
}'
-
Replifier responds with
202and an ID starting withtxm_. Store that ID in your database alongside the order so you can look it up later. Thestatusfield can bequeued,sending,accepted,skipped, orfailed. -
If the server retries the same request (same key, same body), Replifier returns the same
txm_with theIdempotent-Replayed: trueheader. No additional email is sent. -
To receive delivery notifications, create a webhook endpoint from the Replifier dashboard. The secret is shown only once when you create it; store it in a platform secret.
-
On your server, verify the signature of each event before processing it. The
X-Replifier-Signatureheader has the formatsha256=<hex>. ComputeHMAC-SHA256(secret, body_as_text)and compare using constant-time equality:
import { createHmac, timingSafeEqual } from 'node:crypto'
function verifySignature(secret, rawBody, header) {
const expected = 'sha256=' + createHmac('sha256', secret)
.update(rawBody)
.digest('hex')
const a = Buffer.from(expected)
const b = Buffer.from(header)
if (a.length !== b.length) return false
return timingSafeEqual(a, b)
}
- Respond with
200if the signature is valid. Replifier retries events that do not receive a2xxresponse.
What you should see when done
- The first call responds
202with anidstarting withtxm_. - A retry with the same key returns the same
idand theIdempotent-Replayed: trueheader. - In the Replifier dashboard, the send appears in the recipient’s history with its full timeline.


Common issues
- Duplicate emails are arriving: the server is generating a different idempotency key on each retry (for example, a fresh UUID every attempt). Use the order ID as the key — it is already unique and stable.
409 idempotency_conflict: the same key was used with a different body. Generate a new key or investigate why the body changes between retries.- Webhook signature does not match: the HMAC must be computed over the raw body as text, before parsing it as JSON. Also check that you are using the secret for the correct endpoint.
422 recipient_suppressed: the recipient is on your brand’s suppression list (hard bounce, complaint, or unsubscribe). Replifier does not send to suppressed addresses by design.