Skip to content

Idempotent requests

Retry any POST to the EenFactuurMaken.nl API safely with an Idempotency-Key. How replays work, what we store, the error codes and the limits.

A timeout, a flaky connection or a server restart: sometimes you don't know whether a request worked. If you simply try again, you might end up with two invoices or two emails. The Idempotency-Key header prevents that: a retry with the same key returns the first response instead of running the request again.

How it works

Send an Idempotency-Key header with a POST, with a value you pick for this one action:

bash
curl -X POST https://eenfactuurmaken.nl/api/v1/invoices/$INVOICE_ID/send \
  -H "Authorization: Bearer $EENFACTUURMAKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 8d3f1a2b-6c4e-4f5a-9b7c-0e1d2f3a4b5c" \
  -d '{}'
  • It works on every POST under /api/v1: creating, issuing, sending, reminding and marking invoices paid, creating customers and products, quotes, webhooks and so on.
  • The header is optional. Without it, everything works as always.
  • The key is 1 to 255 characters: letters, digits and punctuation, no spaces. A fresh UUID per action works well (uuidgen or crypto.randomUUID()).
  • Pick the key before the first attempt and store it, for example with the order in your database. On a retry, send exactly the same key and the same request.

A few POST requests accept the header but don't use it, because a stored response would be wrong there: POST /invoices/preview-pdf (render a preview PDF), POST /email-domains/{id}/verify (check DNS now) and POST /webhooks/{id}/test (send a test event). We run those every time.

A replay

When a request with the same key and the same request (same method, same path, same query parameters and same body) arrives within 24 hours, we don't run anything again. You get the first response back, with the same status, and the header:

text
Idempotent-Replayed: true

The order of fields in your JSON and whitespace don't matter: {"a":1,"b":2} and { "b": 2, "a": 1 } are the same request.

Same key, different request

If you reuse a key for a different request (another path or another body), you get 422 idempotency_key_mismatch and nothing happens. It usually means your code reuses a key that belongs to another action: create a new key per action.

The first request is still running

If the retry arrives while the first request is still running, you get 409 idempotency_key_in_progress with the header Retry-After: 1. Wait that many seconds and try again with the same key: you then get the response of the first request.

If a server stopped in the middle of a request, the key counts as free after 5 minutes and the next attempt runs the request.

Who a key belongs to

A key belongs to your account. The web app and all your API keys share the same keys, so two integrations that happen to pick the same key get in each other's way; with UUIDs that doesn't happen. Keys of different accounts have nothing to do with each other.

What we store

  • Only successful responses (status 2xx). On an error we store nothing. Once you've fixed the problem you may reuse the same key, even with a changed body: the request then simply runs.
  • We keep the key and the response for 24 hours. After that we delete them, and the same key runs the request again.
  • Responses with a secret or a secret link (a new webhook secret, an issued invoice with its online invoice link, a Stripe payment page) are stored encrypted.
  • The stored response can contain your customers' data, just like the response itself. If you delete your account, it goes too. See Privacy and hosting.

If a stored response can no longer be read (rare), you get 500 idempotency_replay_unavailable. The request already succeeded earlier: look the result up with a GET instead of retrying.

Limits

An Idempotency-Key catches most repeats, but not all:

  • A crash after saving. If our server stops right after a change was saved but before the response was stored, a retry runs the request again.
  • An error after saving. If the main part works but something fails afterwards (for example: the email was sent, but updating the invoice failed), you get an error back and we store nothing. A retry then runs the request again.

So:

  • Also give invoices and customers an externalId. A second create with the same id always returns 409 external_id_taken with the id of what already exists. See Integrate with your SaaS.
  • Before you send an invoice again, check sentAt on the invoice, or GET /emails.
  • The MCP server doesn't use an Idempotency-Key. There, the externalId prevents duplicate invoices.

Examples

Create and issue an invoice, with a key you store with the order:

bash
KEY=$(uuidgen)   # store this with the order
curl -X POST https://eenfactuurmaken.nl/api/v1/invoices \
  -H "Authorization: Bearer $EENFACTUURMAKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $KEY" \
  -d '{ "externalId": "order-1042", "customerExternalId": "cus_9", "issue": true,
        "lines": [ { "description": "Annual subscription", "quantity": "1", "unitPriceCents": 12000, "vatRate": "21" } ] }'
# Timed out? Send exactly the same request with the same $KEY again.

In Node.js, retrying on network errors, 429, 503 and 409 idempotency_key_in_progress:

js
import { randomUUID } from 'node:crypto'

async function post(path, body, key = randomUUID()) {
  for (let attempt = 1; attempt <= 5; attempt++) {
    try {
      const res = await fetch(`https://eenfactuurmaken.nl/api/v1${path}`, {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${process.env.EENFACTUURMAKEN_API_KEY}`,
          'Content-Type': 'application/json',
          'Idempotency-Key': key,
        },
        body: JSON.stringify(body),
      })
      const json = await res.json()
      if (res.ok) return { data: json, replayed: res.headers.get('idempotent-replayed') === 'true' }
      const retry = res.status === 429 || res.status === 503 || json.data?.code === 'idempotency_key_in_progress'
      if (!retry) throw Object.assign(new Error(json.data?.message), { code: json.data?.code, details: json.data?.details })
      await new Promise(r => setTimeout(r, (Number(res.headers.get('retry-after')) || attempt) * 1000))
    }
    catch (err) {
      if (err.code || attempt === 5) throw err // an API error or the last attempt
      await new Promise(r => setTimeout(r, attempt * 1000)) // network error: same key, again
    }
  }
  throw new Error('Too many attempts')
}

All error codes are listed under Errors and limits.

Last updated on 29 October 2026

Stuck?

Email us at support@eenfactuurmaken.nl. Tell us what you tried and what happened, and we will help you out.

support@eenfactuurmaken.nl