# Errors

> The error shape the API returns, every status and code, and what to do about each one.

Every refusal has the same shape, with an HTTP status that matches:

```json
{ "error": { "code": "forbidden", "message": "This API key does not have the 'pay:read' permission.", "details": { "requiredScope": "pay:read" } } }
```

`code` is stable and meant for your program. `message` is written for a person and may be reworded. `details` is present only on some errors.

## Statuses and codes

| Status | Code | Meaning | What to do |
| --- | --- | --- | --- |
| 401 | `unauthorized` | No key, a key that is not recognised, or one that was revoked or has expired | Check the `Authorization: Bearer sfk_…` header. Make a new key if needed |
| 402 | `plan_required` | The organization's plan does not include the API, or the plan has lapsed | Move to Pro, Agency or Enterprise. Keys are kept |
| 403 | `forbidden` | The key lacks the permission this operation needs (`details.requiredScope` names it), or the organization is suspended | Make a key with that permission |
| 403 | `person_required` | The change is one only a person may make in the app: marking an application not moving forward. (Sending a job offer is also a person's act: `POST /api/v1/offers/{id}/send` answers `202` and queues it for a person's approval instead.) | Have someone do it on the Recruit screen |
| 404 | `not_found` | No such record in your organization. Drafts and other organizations' records also answer 404 | Check the id |
| 409 | `conflict` | The record is in a state that does not allow this, for example approving time off that is no longer a request | Read the record and decide again |
| 409 | `email_taken` | Creating or updating a person with an email address another active person already has. The message names them | Use a different address, or update the person who holds it |
| 409 | `overlap` | Correcting a time entry would put it on hours another entry already covers for the same person. The message names the other entry | Change the times, or void the other entry first |
| 409 | `confirm_required` | The change has a consequence you must accept: making a person inactive, or changing their role, while they have upcoming shifts | Read the message, then send again with `"confirm": true` |
| 409 | `request_in_progress` | An earlier request with the same `Idempotency-Key` is still running | Try again in a moment |
| 413 | `too_large` | The body is larger than allowed: 64 KB for JSON, 10 MB for an uploaded file | Send less |
| 415 | `unsupported_type` | A document upload was not sent as `multipart/form-data` | Send the file as a form part named `file` |
| 422 | `validation` | A field is missing, mistyped, unknown or out of range. The message names it | Fix the request. Do not retry unchanged |
| 422 | `constraint_violation` | A scheduling rule refuses the change: eligibility, a credential, time off, an overlap, rest, or the person's work area and travel time. The rule is named | Choose another person or time. The API cannot override a rule |
| 422 | `idempotency_key_reused` | The `Idempotency-Key` was already used with a different request | Use a new key for a new request |
| 429 | `rate_limited` | More than 120 requests in a minute for this key, or too many attempts with a bad key | Wait for the `Retry-After` seconds |
| 502 | `send_failed` | A booking link could not be emailed just now. Nothing is kept as sent | Retry with the same `Idempotency-Key` in a minute |
| 503 | `not_configured` | Video calls or email are not switched on for this workspace yet | Ask Staffedly support |
| 5xx | | Something failed on Staffedly's side | Retry with the same `Idempotency-Key`. Check [the status page](https://app.staffedly.com/status) |

## Unknown fields are refused

A write lists the fields it accepts. Any other field in the body answers `422 validation` and names both the unknown field and the allowed ones. A typo is caught instead of being ignored.

## Which errors to retry

Retry 429 and 5xx, with a growing wait. Do not retry other 4xx answers without changing the request. When you retry a write, send the same [Idempotency-Key](https://staffedly.com/docs/developers/idempotency).
