Handling API errors well
Branch on error.code, retry only what is worth retrying, and reuse the idempotency key when you do.
Owner, Admin · Last checked 25 November 2026 · 2 min read
Every failed call returns the same envelope, so one small wrapper can handle all of them. See API errors for every code.
The rules
- Branch on
error.code. It's stable. error.message is for people and can change.
- Retry only what can succeed later:
409, 429, 500 and 503, with exponential backoff and a little randomness (jitter). On 429, wait the Retry-After seconds first.
- On
401, get a fresh token and retry once. If it still fails, the app was revoked or its secret changed.
- Don't retry
403, 404 or 422. The request is wrong, or the app lacks a scope. Fix it instead.
- Retry writes with the same
Idempotency-Key, so a retry never does the work twice. A new key is for a new write. See Safe retries with idempotency keys.
- Never log the secret or the token. Log
error.code, the status and the path.
A small wrapper
In the example, SKEDULER_API is your Skeduler API address. Contact Skeduler support if you don't have it.
async function call(path, { method = "GET", body, key } = {}) {
const idempotencyKey = method === "GET" ? undefined : key ?? crypto.randomUUID(); // chosen once per write
let refreshed = false;
for (let attempt = 0; attempt < 5; attempt++) {
const res = await fetch(`${process.env.SKEDULER_API}/api/v1${path}`, {
method,
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
...(idempotencyKey && { "Idempotency-Key": idempotencyKey }),
},
body: body && JSON.stringify(body),
});
if (res.ok) return res.json();
const { error } = await res.json().catch(() => ({ error: { code: "server_error" } }));
if (res.status === 401 && !refreshed) { refreshed = true; await getToken({ force: true }); continue; }
if ([409, 429, 500, 503].includes(res.status)) {
const wait = Number(res.headers.get("Retry-After")) * 1000 || Math.min(30000, 500 * 2 ** attempt) * (0.5 + Math.random());
await new Promise((r) => setTimeout(r, wait));
continue;
}
throw Object.assign(new Error(error.message), { status: res.status, code: error.code, fields: error.fields });
}
throw new Error("Gave up after 5 attempts");
}
getToken() returns a cached token and asks for a new one shortly before it expires. See How long does an access token last?.
Showing a problem to a person
For 422 validation_failed, error.fields has a message for each field you can show next to the right box. See My request fails with validation_failed. A 500 is always server_error: tell the person something went wrong on Skeduler's side and that you'll try again, rather than showing a raw response.
API errors
Every error code the Skeduler API returns, what it means, its likely cause and how to fix it, plus the token endpoint's OAuth errors.
Owner, Admin · Last checked 24 November 2026 · 4 min read
A failed call returns an HTTP status and one JSON envelope:
{ "error": { "code": "validation_failed", "message": "The title field is required.", "fields": { "title": ["The title field is required."] } } }
- Branch on
error.code. It's stable. The message is for people and can change.
error.fields appears only for validation_failed, with the messages for each field.
- The token endpoint is the one exception. It answers in the OAuth format, for example
{ "error": "invalid_client" }.
Codes
| Status | error.code | What it means, and the likely cause | How to fix it |
|---|
| 401 | unauthenticated | No token, or a malformed, expired or revoked one. Suspending or revoking an app deletes its tokens, so its calls get this too. | Get a new token and retry once. If it fails again, check the app hasn't been suspended or revoked, and that you're using its current secret. |
| 403 | insufficient_scope | The token lacks the scope the call needs (the message names it). On webhook subscribe, the app lacks the read scope of the event's records. | Give the app that scope, then get a new token. See Who can grant which scopes. |
| 403 | app_inactive | The business's account is no longer active. | Nothing in your request. The business needs its Skeduler account active again. |
| 403 | billing_restricted | The business's subscription restricts API access. | Nothing in your request. The business's Owner or an Admin sorts out the subscription in Skeduler, and calls work again once access is back. |
| 404 | not_found | No such record in this business. Archived records and other businesses' ids look the same, and so does an unknown path. | Check the id and the path. The record may be archived, or belong to another business. |
| 405 | method_not_allowed | The path exists, but not for that method. | Use the method the endpoint list gives for that path. |
| 409 | idempotency_in_progress | A request with the same Idempotency-Key is still being processed. | Wait a moment, then retry with the same key. You'll get the first request's answer. |
| 409 | idempotency_replay_unavailable | The first answer for this Idempotency-Key can no longer be replayed. | Check whether the first request took effect (for example, read the record), then retry with a new key. |
| 422 | validation_failed | A field is missing or wrong, a filter value isn't valid, or a name you referenced doesn't exist (for example a job status). | Read error.fields, fix those fields and send it again. |
| 422 | invalid_event | Webhook subscribe: unknown event. | Use an event from Webhook events and their payloads. |
| 422 | invalid_target_url | Webhook subscribe: target_url isn't an https:// URL of up to 2048 characters with a public address. | Use a public https:// address of up to 2048 characters. |
| 422 | subscription_limit_reached | Webhook subscribe: 50 active subscriptions for the app, or 200 for the business. | Delete subscriptions you no longer use, then subscribe again. |
| 422 | invalid_idempotency_key | The Idempotency-Key isn't 1 to 255 printable ASCII characters, or it's missing on POST /invoices/{id}/payments, where it's required. | Send a key of 1 to 255 printable ASCII characters, such as a UUID. Always send one when recording a payment. |
| 422 | idempotency_key_reused | The key was already used for a different request. | Use a new key for each new request. Reuse a key only to retry the exact same request. See My request fails with idempotency_key_reused. |
| 429 | rate_limited | Over a rate limit. | Wait Retry-After seconds, then retry. Spread your calls out. See Staying under the rate limits. |
| 500 | server_error | Something went wrong on Skeduler's side. | Retry with backoff. If it keeps happening, contact Skeduler support with the time and the call you made. |
| 503 | api_disabled | The API is switched off for a while. | Try again later, with backoff. |
Token endpoint errors
POST /api/v1/oauth/token answers in the OAuth format, { "error": "<code>" }, with no message.
| Status | error | What it means, and the likely cause | How to fix it |
|---|
| 401 | invalid_client | The client ID or secret is wrong, or the app can't get tokens any more. | Check both values. If the secret is lost, rotate it. See Token request fails with invalid_client. |
| 400 | invalid_request | You sent the client ID and secret both in the Authorization header and in the body. | Send them one way only: the header (HTTP Basic) or the body. |
| 400 | unsupported_grant_type | grant_type isn't client_credentials. | Send grant_type=client_credentials. |
Handling them
- 401: get a new token and retry once. If it still fails, the app was suspended or revoked, or its secret changed.
- 403: don't retry. Fix the scope, or the app or billing problem.
- 409, 429, 500, 503: retry with exponential backoff and a little random delay. Honour
Retry-After on a 429. If you sent an Idempotency-Key, retrying a write is safe.
- 404, 422: the request itself is wrong. Sending it again won't help.
My request fails with validation_failed
A field is missing or wrong. The error says which one in error.fields.
Owner, Admin · Last checked 25 November 2026 · 1 min read
What you see
422 with error.code of validation_failed:
{ "error": { "code": "validation_failed", "message": "The title field is required.", "fields": { "title": ["The title field is required."] } } }
error.fields lists the messages for each field. message is the first of them.
Why it happens
- A required field is missing.
- A filter value isn't valid.
updated_since isn't a real date, such as 2026-02-30.
cursor isn't one the API issued.
- A name you referenced doesn't exist.
- A visit time has no UTC offset.
end_at isn't after start_at.
- A payment is more than what's due, or the invoice is a draft, void or cancelled.
How to fix it
- Add the missing field. For example, a job needs a
title.
- Use an allowed
status, and ids that are ULIDs.
- Send a valid ISO 8601 date or timestamp.
- Pass back
meta.next_cursor exactly. Don't build one.
- A job status name must match one of the business's active statuses. See Change a job's status.
- Send
2026-12-01T09:00:00+11:00 or …Z.
- Fix the times.
- See Record a payment on an invoice.
Retrying the same request won't help. Fix the request. If you sent an Idempotency-Key, the refusal is stored, so send the corrected request with a new key. See What happens if I reuse an idempotency key with a different body?.
See API errors for every code.