Core Concepts
Errors & Idempotency
One JSON error body with a stable code, what each status means, when to retry, and the Idempotency-Key header.
Every error the API returns on purpose has the same JSON body. Each endpoint page lists the errors that endpoint can return, with their codes.
The error body
| Field | Meaning |
|---|---|
code | Stable, machine-readable code such as campaign_not_found. Match on it. |
statusCode | The HTTP status of the response. |
message | What went wrong, written for people. It can change; do not parse it. |
_tag | The error's name, such as CampaignNotFound. |
Extra fields
A few errors carry more fields to act on:
| Code | Status | Extra fields |
|---|---|---|
rate_limited | 429 | retryAfterSeconds: how long to wait before trying again. |
subscription_required | 402 | preview_leads, plus subscribe_method and subscribe_path: the call that subscribes. |
credits_exhausted | 402 | remaining, plus subscribe_method and subscribe_path. |
team_seat_unavailable | 402 | granted: how many seats the plan has. |
plan_not_found | 404 | planId: the plan that does not exist. |
workspace_website_unreadable | 502 | domain: the website Bavlio could not read. |
Invalid requests
A body, path, query or header that does not match the endpoint's schema is answered with 400 invalid_body, and message describes the first problem found. A body that is not valid JSON gets the message Expected a valid JSON body. Saving a sequence answers 400 sequence_invalid instead.
Answers without a JSON body
- A path the API does not have is answered with
404and an empty body. - A request body sent with a content type other than JSON is answered with
415and a plain-text body. - An unexpected failure on Bavlio's side is answered with an empty
500.
Status codes and retry rules
| Status | Meaning | Retry? |
|---|---|---|
| 200 | OK | n/a |
| 201 | Created | n/a |
| 204 | Done, with nothing to return | n/a |
| 400 | The request is invalid: fix it | no |
| 401 | The credential is missing or rejected | no (fix the credential) |
| 402 | The plan does not cover this: subscribe, or add credits or seats | no |
| 403 | Your role, or an unverified email address, does not allow this | no |
| 404 | Nothing with this id in the workspace, or no such path | no |
| 409 | The request conflicts with the current state | maybe (after a read) |
| 415 | The request body is not JSON | no |
| 429 | Too many of this action for now | yes (after retryAfterSeconds) |
| 500 | Unexpected failure | yes (exponential backoff) |
| 502 | A service Bavlio relies on failed | yes (exponential backoff) |
| 503 | Bavlio or a service it relies on is unavailable right now | yes (exponential backoff) |
A safe default: retry 429 after retryAfterSeconds, retry 5xx with exponential backoff (at most 5 attempts), and surface everything else straight away.
Idempotency
The two endpoints that send a message to a lead accept an Idempotency-Key header: Send a reply and Approve a review. Use a new unique value, such as a UUID, for every send. It can be 1 to 255 characters long and is remembered for 24 hours in the workspace.
| You send the same key again and… | Answer |
|---|---|
| the first call finished | The first call's outcome. Nothing is sent twice. |
| the first call is still running | 409 idempotency_key_in_use: wait a moment and try again. |
| the first call's outcome is unknown | 409 idempotency_key_in_use: check the conversation, and send again only with a new key. |
| the body differs from the first call's | 400 idempotency_key_reused. |
| the first call failed before sending | The key is free again: the retry is a fresh attempt. |
No other endpoint takes the header. After a network failure on any other write, read the current state first and retry only if the first call did not land.
FAQ
How do I tell if I should retry?
How do I tell if I should retry?
Retry on 429 after the retryAfterSeconds in the body, and on 5xx with exponential backoff. Do not retry other 4xx answers: fix the request and send it once. The code names the exact cause.
What is the error body?
What is the error body?
{ _tag, statusCode, code, message }, plus a few extra fields on some errors. Match on code; message is for people.
What is the difference between 401 and 403?
What is the difference between 401 and 403?
401 means the credential is missing, malformed, revoked or expired: fix it. 403 means the credential is fine but your role in the workspace does not allow the call, or the call needs a verified email address.