When the REST API refuses a request, the answer is JSON with a stable code, a sentence for people, and whether sending it again can help.
The error shape
{
"code": "validation_failed",
"message": "The body field is required.",
"request_id": "01M88Q4X0Q7ZH6VG1VA35RVVQJ",
"retryable": false,
"details": {
"body": ["The body field is required."]
}
}
| Field | What it is |
|---|---|
code |
A stable name for what went wrong. Branch on this, never on the message. |
message |
One or two sentences for a person. The wording can change. |
request_id |
The id of the request, the same value as the X-Request-Id header. Quote it when you ask us about a request. |
retryable |
true when the same request can succeed later without being changed. |
details |
More about the error, when there is more. Left out otherwise. |
Status and code
The HTTP status tells you the kind of problem; the code says which one. Every code, with its status:
| Code | HTTP status | What it means | Can a retry help |
|---|---|---|---|
access_denied | 403 | The key's scope or the person's role does not allow this. | No |
not_found | 404 | Nothing with that id exists in this workspace. An id that belongs to another workspace gives the same answer. | No |
validation_failed | 422 | A value is missing or not valid. The message says which, and details names the fields when the request itself was malformed. | After the request is corrected |
version_conflict | 409 | What you sent was built on an older state: someone changed it, or it was already decided. | After reading the current state again |
quota_exceeded | 429 | A plan limit is reached, the plan does not include the feature, or the same thing was asked for too often in a short time. The message says which. | After the month turns, a plan change, or the wait the message names |
feature_unavailable | 422 | The feature or integration is switched off, not authorized yet, or not part of the plan. | No |
connection_required | 422 | The channel, ad account or CRM is not connected, or its access has expired. | After a person connects it again |
needs_authorization | 422 | The integration is built but not authorized or configured yet, so it cannot be used. | No |
approval_required | 422 | A person has not approved this in the app yet. | After a person approves in the app |
approval_invalid | 409 | The approval no longer covers this exact content, channel and time. Nothing was sent. | After a new approval |
provider_rejected | 422 | The outside service refused the request. | Only when the message names something you can change |
provider_unavailable | 503 | The outside service did not answer or is having trouble. | Yes, later |
publication_uncertain | 422 | The channel gave no clear answer, so it is not known whether the post exists. The post is marked as uncertain until a person says what happened. | No. A person checks the channel first |
duplicate | 409 | The same thing already exists or is already under way. | No |
consent_required | 422 | The person asked not to be contacted and is on the suppression list. | No |
unsupported | 422 | The channel, connection or format cannot do this. | No |
confirmation_required | 422 | An assistant must ask the person and send person_confirmed: true before this is recorded. | After the person says yes |
unauthenticated | 401 | The key is missing, mistyped, revoked or expired, or its workspace is no longer active. | After the key is corrected |
rate_limited | 429 | Too many requests in a minute. | Yes, when the minute has passed |
request_failed | 4xx | Another refused request, for example a method the address does not take. The HTTP status says which. | After the request is corrected |
server_error | 5xx | Something failed on our side. The request_id finds it in our logs. | Yes, later. Send the same Idempotency-Key |
For a call to the REST API, some of them mean something more exact:
unauthenticatedandaccess_denied: see Authentication.not_foundis also the answer for an address that does not exist.request_failedwith the status405: the address exists but not with that method.version_conflict: the item changed since thelock_versionyou sent.duplicate: theIdempotency-Keywas used with another request, or the first request with it is still running.validation_failedalso covers a thing that is not in a state that allows the request.quota_exceeded: the workspace is read-only because the plan allows fewer workspaces than the organization has. Waiting does not help.server_errorwith the status503: the service is briefly unavailable, andretryableistrue.
An unexpected failure on our side answers 500. Its body is JSON but may hold only a message, without a code. Treat every 5xx as something to retry.
Validation details
For validation_failed, details usually has one entry for each field that was refused, and each entry is a list of sentences. Nested fields are written with dots, items of a list with their position:
{
"code": "validation_failed",
"message": "account.currency is required: amounts are never stored without a currency and it is never guessed.",
"request_id": "01M88Q4X5Y22WW5DJB5RA9FCXX",
"retryable": false,
"details": {
"account.currency": ["account.currency is required: amounts are never stored without a currency and it is never guessed."]
}
}
Some errors carry other facts in details instead:
| Where | details |
|---|---|
| A planned time the clocks skip | {"reason": "dst_gap"} |
version_conflict |
{"current": 3}: the lock_version the item has now |
| An approval request that is not ready | {"issues": [...]}: what the checks found |
quota_exceeded |
{"limit_key": "workspaces", "plan": "..."} |
Errors inside a batch
The operations that take a batch do not fail as a whole because one item is wrong. They answer 200 and report each item:
- Send CRM records in a batch:
failed, andresult: "error"on the record. - Import ad results:
rows_failed, anderrorswith the index of each row. - Send events:
rejected, andstatus: "rejected"witherrorson the event.
So a 200 is not the end of the check. Read the counts.
How to retry
Retry when retryable is true, when the status is 5xx, and when no answer arrived at all. Do not retry anything else: the same request will get the same answer.
- Send the retry with the same
Idempotency-Keyand the same body as the first attempt. If the first attempt did go through, you get its answer back instead of a second draft or a second import. See idempotency. - Wait before each retry, and wait longer each time: for example 1, 2, 4, 8 seconds, each with a little random spread, and stop after a handful of attempts.
- After
429rate_limited, wait the number of seconds in theRetry-Afterheader. - After
409duplicatewithretryable: true, the first request is still running. Wait a second or two and send it again to get its answer. - After a
4xxthat is not retryable, change the request. A changed request needs a newIdempotency-Key.
Keep the request_id of a failure you cannot explain. With it we can find the request. One answer leaves it out of the body: a single event that is not valid (Send events). The X-Request-Id header is still there.