Skip to content
HeyMySocial

API errors

The one shape every API error has, how HTTP status and error code go together, what retryable and details mean, and how to retry safely.

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:

CodeHTTP statusWhat it meansCan a retry help
access_denied403The key's scope or the person's role does not allow this.No
not_found404Nothing with that id exists in this workspace. An id that belongs to another workspace gives the same answer.No
validation_failed422A 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_conflict409What you sent was built on an older state: someone changed it, or it was already decided.After reading the current state again
quota_exceeded429A 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_unavailable422The feature or integration is switched off, not authorized yet, or not part of the plan.No
connection_required422The channel, ad account or CRM is not connected, or its access has expired.After a person connects it again
needs_authorization422The integration is built but not authorized or configured yet, so it cannot be used.No
approval_required422A person has not approved this in the app yet.After a person approves in the app
approval_invalid409The approval no longer covers this exact content, channel and time. Nothing was sent.After a new approval
provider_rejected422The outside service refused the request.Only when the message names something you can change
provider_unavailable503The outside service did not answer or is having trouble.Yes, later
publication_uncertain422The 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
duplicate409The same thing already exists or is already under way.No
consent_required422The person asked not to be contacted and is on the suppression list.No
unsupported422The channel, connection or format cannot do this.No
confirmation_required422An assistant must ask the person and send person_confirmed: true before this is recorded.After the person says yes
unauthenticated401The key is missing, mistyped, revoked or expired, or its workspace is no longer active.After the key is corrected
rate_limited429Too many requests in a minute.Yes, when the minute has passed
request_failed4xxAnother refused request, for example a method the address does not take. The HTTP status says which.After the request is corrected
server_error5xxSomething 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:

  • unauthenticated and access_denied: see Authentication.
  • not_found is also the answer for an address that does not exist.
  • request_failed with the status 405: the address exists but not with that method.
  • version_conflict: the item changed since the lock_version you sent.
  • duplicate: the Idempotency-Key was used with another request, or the first request with it is still running.
  • validation_failed also 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_error with the status 503: the service is briefly unavailable, and retryable is true.

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:

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.

  1. Send the retry with the same Idempotency-Key and 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.
  2. 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.
  3. After 429 rate_limited, wait the number of seconds in the Retry-After header.
  4. After 409 duplicate with retryable: true, the first request is still running. Wait a second or two and send it again to get its answer.
  5. After a 4xx that is not retryable, change the request. A changed request needs a new Idempotency-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.