Booking idempotency
Never two bookings or two invoices: the booking key, the payment reference, the retry algorithm.
A timeout, a dropped connection, a restarted worker: your system does not know whether the booking was created. It must be able to retry without ever producing two bookings, two agreements or two invoices. The API guarantees it at three levels.
1. The booking key
Idempotency-Key is mandatory on POST /car-rental/bookings: generate a UUID v4 per intended booking, store it with your request, and send it unchanged on every attempt.
# One key per operation, reused as is on every retry.
curl -X POST 'https://quosuite.com/api/public/v1/quosuite/car-rental/bookings' \
-H "Authorization: Bearer $QUOSUITE_API_KEY" \
-H 'Idempotency-Key: 3f1c2a9e-5b7d-4e8a-9c1f-2d6b8e4a7c30' \
-H 'Content-Type: application/json' \
-d '{
"vehicleId": "0b3c5d7e-9f1a-4b2c-8d4e-6f7a8b9c0d1e",
"startAt": "2026-12-20T09:00:00Z",
"endAt": "2026-12-27T09:00:00Z",
"driver": {
"firstName": "Sami",
"lastName": "Ben Ali",
"email": "sami@example.tn",
"birthDate": "1990-04-12",
"drivingLicenseNumber": "TN-123456",
"drivingLicenseIssuedAt": "2012-05-01"
},
"payment": {
"mode": "AGENCY"
},
"acceptTerms": true
}'| Situation | Response |
|---|---|
| first successful call | 201, Idempotent-Replayed: false |
| same key, same body, within 24 h | 201 replayed — the same response, Idempotent-Replayed: true |
| same key, same body, after 24 h (or from another API key of the workspace) | 201, the same booking, Idempotent-Replayed: true |
| same key, another vehicle or other dates | 422 IDEMPOTENCY_KEY_REUSED (detail.bookingId) |
| same key, first call still running | 409 IDEMPOTENCY_IN_PROGRESS — retry in a moment |
| key missing | 400 IDEMPOTENCY_KEY_INVALID |
Two barriers: the API’s memory (24 h, per API key) and the key kept with no expiry on the booking itself, under a unique index of the workspace. Two simultaneous attempts, on two servers, never create two bookings. A rejected call (vehicle taken, driver refused) does not retain the key: once fixed, the next attempt creates.
Within 24 h, the interceptor compares the whole body and replays the original response. Read GET /car-rental/bookings/{id} for the current status. After that window, or through another API key, the durable check compares vehicle and dates only: changing the driver, agencies or options does not update the existing booking.
2. Payment: one reference, one payment
A payment recorded through the API — PREPAID creation or POST /car-rental/bookings/{id}/payments — is recorded once per reference (payment.reference / reference):
POST/car-rental/bookings/{id}/payments
# One key per operation, reused as is on every retry.
curl -X POST 'https://quosuite.com/api/public/v1/quosuite/car-rental/bookings/9f8e7d6c-5b4a-4392-8170-6f5e4d3c2b1a/payments' \
-H "Authorization: Bearer $QUOSUITE_API_KEY" \
-H 'Idempotency-Key: 3f1c2a9e-5b7d-4e8a-9c1f-2d6b8e4a7c30' \
-H 'Content-Type: application/json' \
-d '{
"amount": 834,
"reference": "PSP-778812",
"method": "CARD"
}'- replayed with the same reference: nothing is recorded twice; an interrupted posting (agreement created, invoice not yet) is completed, never doubled;
- each deposit or balance payment uses its own reference; partial payments are allowed up to
amounts.balanceDue; - a reference already used on another booking: 409
CONFLICT(detail.rule: PAYMENT_REFERENCE_USED); - another reference on a fully paid booking: 409
CONFLICT(detail.rule: ALREADY_PAID); - a new payment above the remaining balance: 422
BUSINESS_RULE_VIOLATION(detail.rule: PAYMENT_AMOUNT_MISMATCH); forPREPAIDcreation the limit is the total and an omitted amount defaults to that total.
The posting itself re-reads what exists at each step. A first posting paid in full creates or reuses the agreement and issues the invoice. A partial-payment posting confirms the booking and posts an advance without an invoice. Later balance payments add receipts to the reservation or agreement and allocate them to an existing invoice; they do not automatically create a missing agreement or invoice. erp.posted alone does not mean an invoice exists.
3. The retry algorithm
async function book(request) {
request.key ??= crypto.randomUUID(); // once, stored with the request
for (let attempt = 0; attempt < 6; attempt++) {
let res;
try {
res = await fetch(`${BASE}/car-rental/bookings`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.QUOSUITE_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': request.key,
},
body: JSON.stringify(request.body),
});
} catch {
await sleep(2 ** attempt * 500); // network: unknown outcome — same key
continue;
}
if (res.status === 201) return (await res.json()).data;
if (res.status === 409 || res.status === 429 || res.status >= 500) {
const { error } = await res.json();
if (error.code === 'CONFLICT') throw new Error('Vehicle taken: run a new search');
await sleep((Number(res.headers.get('Retry-After')) || 2 ** attempt) * 1000);
continue;
}
throw new Error(`Rejected (${res.status}): do not retry as is`);
}
throw new Error('Still failing: keep the key and retry later');
}Actions on a booking (…/pickup, …/return, …/cancel, …/payments) also accept Idempotency-Key; POST /car-rental/customers is idempotent by nature (one email = one customer).