Retry Strategy
What to Retry
Only retry idempotent operations or those with transient failures:Exponential Backoff
Timeouts
Set a reasonable timeout on all HTTP requests. The CleanLife API is not expected to take more than a few seconds, but network conditions vary. Recommended timeout: 30 seconds per requestIdempotency (Booking Creation)
Although theIdempotency-Key header is currently disabled, you can achieve safe retries using externalReference:
- Before calling
POST /partners/bookings, generate a unique reference (e.g., UUID or your internal order ID). - Store this reference in your database with status
PENDING. - Call the API with
externalReferenceset to this value. - If the request fails with a network error or timeout:
- If you receive
409 DUPLICATE_EXTERNAL_REFERENCE, the booking was created successfully — use thebookingIdyou stored from the original response, or treat the conflict as confirmation that creation succeeded. - If you receive
422 BOOKING_CREATION_FAILED, the booking failed — retry with the sameexternalReference. - If you receive no response, retry only if you have not yet received a
409; otherwise pollGET /partners/bookings/:bookingId/statususing a storedbookingId.
- If you receive
Logging
Log the following for every API call to enable debugging and auditing:Error Handling
Build a structured error handler that distinguishes between error categories:Security
- Store API Key as a secret, not in code. Use environment variables or a secrets manager (e.g., AWS Secrets Manager, HashiCorp Vault, Azure Key Vault).
- Use HTTPS for all API calls.
- Restrict your API Key to a specific IP range if possible. Contact CleanLife to configure an IP allowlist.
- Rotate your API key periodically.
Performance
Cache the Service Catalog
Services change infrequently. Cache this response:Do Not Cache Timeslots
Available timeslots change in real time as bookings are created. Always query fresh.Pagination
Uselimit=100 (the maximum) when fetching paginated catalog lists to minimize the number of API calls.
Testing
- Use a distinct
externalReferenceprefix for test bookings (e.g.,TEST-) to identify them in production logs. - Test cancellation and payment confirmation flows end-to-end before going live.