Guides
Errors
Every failure is a stable code, a sentence for a human and a request id. Branch on the code; show the sentence; log the id.
The envelope
The status tells you the class of problem and whether to retry. The code tells you which problem it is, and is the only part safe to write logic against: messages are rewritten for clarity, codes are not.
{"error": "Validation failed","code": "validation_failed","details": [{ "code": "too_small", "path": ["name"], "message": "Too small: expected string to have >=1 characters" }],"requestId": "3f6c1a52-8d0e-4b7a-9c1e-2a4b6d8f0e13"}
- error
- A sentence for a person reading a log or a toast.
- code
- Stable. Comes from the status unless the failure has a more specific one.
- details
- Present when there is more to say: the issue list on
validation_failed,{ required: ["module:action"] }onforbidden, the plan facts on a402. - requestId
- The same id as the
X-Request-Idheader, which every response carries. Send your ownX-Request-Idand it is echoed back, so your logs and ours line up.
Codes
- 400validation_failed
- The body or query failed validation. details is the list of issues, each with the path it is about.Read details rather than the message: it is field by field. Do not retry unchanged.
- 400invalid_request
- The request is wrong in a way that is not about one field: an unknown event type, a batch path outside /api/v2.The message says what; fix the call.
- 401unauthorized
- No credential, or an invalid, expired or revoked key.Check the header and the key; issue a new one if it was revoked.
- 402plan_required
- The workspace's plan does not include this feature.details.requiredPlan names the plan that does. Not retryable until the plan changes.
- 402plan_limit
- The workspace has reached a limit of its plan: seats, queues, pages this month or API keys.details carries the limit, its value, what is used and the plan that lifts it.
- 403forbidden
- Authenticated, but not allowed: the permission is missing (details.required), or the endpoint needs a signed-in person.Ask GET /api/v2/whoami what the key holds; issue a key with the scope.
- 404not_found
- Not in the caller's workspace, or not visible to them. The two answer the same way.Check the id, then the key’s workspace and queue access.
- 409conflict
- The request fights the current state, or a request with the same Idempotency-Key is still running.Re-read the resource; for an idempotent retry, wait a moment and send it again.
- 413payload_too_large
- The upload or body is over the size the endpoint accepts.Split it, or send a smaller file.
- 415unsupported_media_type
- The file type or Content-Type is not one the endpoint takes.Check the endpoint’s content type and the file format.
- 422idempotency_conflict
- This Idempotency-Key was already used with a different request body.A bug in the caller: use a new key for each distinct request. Do not retry.
- 429rate_limited
- Over the caller's requests per minute.Wait for Retry-After, then continue. details carries limit and resetAt.
- 500internal_error
- Ours, not yours.Retry with backoff; if it persists, send us the requestId.
Plan refusals
A plan refusal is 402, not 403: the caller is allowed to do this, the workspace's plan is what stops it, and the fix is an upgrade rather than a role. Limits are counted live, at the moment of the write. GET /api/v2/workspace shows the plan, each limit and how much of it is used, so an integration can see a plan_limit coming.
{"error": "The Free plan allows 2 queues in a workspace, and this one has 2.","code": "plan_limit","details": { "limit": "queues", "plan": "free", "requiredPlan": "pro", "limitValue": 2, "used": 2 },"requestId": "3f6c1a52-8d0e-4b7a-9c1e-2a4b6d8f0e13"}
plan_required carries { feature, plan, requiredPlan } instead. Work that was set up on a richer plan keeps its configuration: a source pauses with its place kept, an automation is skipped, a destination fails visibly.
Handling them
Three groups, and they want different things: retry with a wait (429, 5xx), fix the request and do not retry (400, 409, 422), or fix the credentials or the plan (401, 402, 403).
async function approve(documentId) {const response = await fetch(`https://docuflow.pendral.io/api/v2/documents/${documentId}/approve`, {method: "POST",headers: {Authorization: `Bearer ${process.env.DOCUFLOW_API_KEY}`,"Content-Type": "application/json",},body: "{}",});if (response.ok) return response.json();const { code, error, details, requestId } = await response.json();switch (code) {case "rate_limited": {const wait = Number(response.headers.get("Retry-After") ?? 5);await new Promise((resolve) => setTimeout(resolve, wait * 1000));return approve(documentId);}case "validation_failed":// Not worth retrying: the request is wrong, not the moment.throw new BadRequest(details);case "unauthorized":case "forbidden":throw new Misconfigured(error, details?.required);default:throw new Error(`${error} (${requestId})`);}}
Log the whole envelope
code, details and requestId as well as the message. GET /api/v2/logs finds the same request by its id in your workspace's own recent traffic.Credential failures are covered in authentication; the retry budget is in rate limits; repeating a write safely is in idempotency.