Networks fail mid-request. Idempotency keys make retrying a write safe: the same attempt can never create two orders, two memberships, or two charges.
Send an Idempotency-Key header on write operations. The value must be a lowercase UUID v4, generated fresh for each logical attempt and reused for every retry of that attempt.
curl -X POST "https://www.membber.com/api/v1/orders" \
-H "Authorization: Bearer $MEMBBER_TOKEN" \
-H "Idempotency-Key: 1f0e2d3c-4b5a-4678-9abc-def012345678" \
-H "Content-Type: application/json" \
-d '{ ... }'import { createMembberClient } from "@membber/sdk-ts";
const membber = createMembberClient({
getAccessToken: () => process.env.MEMBBER_TOKEN,
});
// One key per logical attempt: generate it when the user taps Pay,
// reuse it for every retry of that same attempt.
const idempotencyKey = crypto.randomUUID();
const { data, error } = await membber.createOrder({
headers: { "Idempotency-Key": idempotencyKey },
body: { /* ... */ },
});Operations that move money or create customer records, such as creating orders and memberships, require the header outright: calling them without one returns 400 IDEMPOTENCY_KEY_REQUIRED, so the API tells you rather than leaving it to memory. All other writes are idempotent at the data layer, which means retrying them cannot double-apply; the header is accepted and ignored there, so the simplest correct client sends it on every write.
422 IDEMPOTENCY_KEY_REUSED. A key identifies one attempt; changing the payload means a new attempt and a new key.400 VALIDATION_ERROR.