# Errors

Every error code, what it means and how to fix it.

> Part of [Tayl's API docs](https://tayl.pro/api/v1/docs.md): requests go to `https://tayl.pro` with `Authorization: Bearer <key>`.

Every error comes back in the same envelope, with an HTTP status and a machine-readable `code`; [Conventions](https://tayl.pro/api/v1/docs/conventions.md) describes it. Branch on the status and `code`, not on `message`. Each code below says what it means and how to fix it, and an error's `documentation_url` links straight to its entry.

An unexpected `500`, and a few framework errors raised before the API runs, such as an unreadable query string, can arrive without this envelope, so parse errors defensively.

## Authentication and access

### missing_token

`401`. The request had no `Authorization: Bearer` header.

**Fix:** Send the API key as `Authorization: Bearer tayl_live_…`. An organisation admin creates keys in Tayl under **Settings > Public API**.

### invalid_token

`401`. The key isn't recognised, or it has been revoked or has expired. A personal key also stops working once its person no longer has access to the organisation. An upload link from `tayl_upload_image` lasts an hour, and only while its key works.

**Fix:** Check the whole key was sent, without extra spaces. If it was revoked or expired, ask an organisation admin for a new one, or the person to create a new personal key in Tayl. For an upload link, call `tayl_upload_image` again for a new one.

### organisation_restricted

`402`. The organisation's account needs attention: its plan does, for example it's over the Free plan's limit after a paid plan ended, or Tayl has put it on hold. Every request with its keys except `GET /api/v1/api-keys/current`, whose `restriction` gives the reason, is refused until it's resolved.

**Fix:** Don't retry automatically. Ask an organisation admin to resolve it in Tayl, or to contact Tayl about a hold; requests work again as soon as it's resolved.

### insufficient_scope

`403`. The key doesn't hold the scope this operation needs. The message names it.

**Fix:** Ask an organisation admin to add the scope to the key in Tayl under **Settings > Public API**, or the person to create a personal key that includes it. `GET /api/v1/api-keys/current` shows which scopes the key holds.

### not_permitted

`403`. The key can't do this in Tayl, whatever scopes it holds. A personal key's person may have no role that allows it, or the record may be one they can see but not change, such as an admin in a group they manage. An Organisation Group Admin can be changed only by Tayl staff or a fellow group admin, including with their own personal key.

**Fix:** Don't retry. Ask someone whose role allows it to make the change in Tayl. `GET /api/v1/api-keys/current` shows what the key can do.

### personal_keys_disabled

`403`. The key is a personal key, and an admin has turned off personal API keys and AI assistants for the organisation. Organisation keys still work.

**Fix:** Don't retry automatically. Ask an organisation admin to turn them on in Tayl under **Settings > Public API**.

### organisation_unavailable

`403`. The key is a personal key whose person can't use the organisation in Tayl for now, because it's being set up or is in maintenance, or its Free plan is inactive. Every request except `GET /api/v1/api-keys/current` waits, as they do. Organisation keys still work.

**Fix:** Don't retry automatically. Requests work again as soon as the person can use the organisation in Tayl again.

### course_builder_unavailable

`403`. The organisation's plan doesn't include Course Builder, which every course authoring write needs.

**Fix:** An admin or billing admin adds Course Builder in Tayl under **Settings > Features**.

### reporting_unavailable

`403`. The organisation's plan doesn't include Advanced reporting, which the Reports summaries need. Tasks, completions and certificates can still be listed.

**Fix:** Don't retry automatically. An admin or billing admin adds Advanced reporting in Tayl under **Settings > Features**.

### rate_limited

`429`. The key sent more requests per second than its limit allows, or its organisation is already downloading as many images from URLs as it may at once.

**Fix:** Wait at least the `Retry-After` seconds, then retry with jitter.

## Request problems

### bad_request

`400`. The request couldn't be read, for example malformed JSON, a missing required field, an invalid filter or pagination value, or a value of the wrong type.

**Fix:** Correct the request as the message describes, then send it again.

### unknown_query_param

`400`. The request had a query parameter this operation doesn't accept. Unknown parameters are refused rather than ignored.

**Fix:** Remove it, or check the operation's parameters for the right name.

### unexpected_request_body

`400`. A body was sent to an operation that takes none. Such operations act only on what their URL names.

**Fix:** Send no body, or an empty object `{}`.

### bulk_limit_exceeded

`400`. A bulk request had more than 500 entries.

**Fix:** Split it into batches of 500 or fewer.

### unsupported_field

`400`. The request set a field that's no longer supported, such as an assignment's `required`.

**Fix:** Remove the field named in `pointer`.

### not_found

`404`. Nothing with that ID exists in the key's organisation, a personal key's person can't see it in Tayl, or the URL isn't an API endpoint.

**Fix:** Check the ID and that it belongs to this organisation, and check the path against the docs at https://tayl.pro/api/v1/docs.md. A personal key reaches only what its person can see, such as a manager's own groups.

### request_too_large

`413`. The request body is bigger than this operation accepts.

**Fix:** Send less at once, for example one chapter or page of a course instead of the whole course.

## Validation and conflicts

### validation_error

`422`. A field's value isn't valid. `field` and `pointer` say which one.

**Fix:** Correct each field named and send the request again. In bulk requests, retry only the failed entries.

### duplicate_external_id

`409`. Another record in the organisation already has this `external_id`. `existing_id` is that record's Tayl UUID, when the key can see it.

**Fix:** Update the existing record instead, or use a different `external_id`.

## People and groups

### invalid_state_transition

`422`. The person can't move to the requested state from their current one, for example restoring someone who isn't archived.

**Fix:** Read the person's current `state` first and only request a change it allows.

### would_lock_out

`422`. The change would lock someone out of running the organisation: nobody can pause or archive themselves, the organisation's last admin, or its group's last group admin.

**Fix:** Don't retry. Make someone else an admin or group admin first, or have someone else make the change.

### invalid_user_state

`422`. An archived person's group memberships can't be changed.

**Fix:** Restore the person first, or leave their memberships as they are.

### automatic_group_read_only

`422`. Automatic groups and their memberships are managed by Tayl.

**Fix:** Change a manual group instead, or change the automatic group's rules in Tayl.

### category_made_group_read_only

`422`. Tayl made this group as a group category's subgroup (`category_made: true`), so Tayl names it and keeps it up to date. Its memberships can still be changed.

**Fix:** Change the groups it combines instead, or turn the category's subgroups off in Tayl to hide it.

### group_not_deletable

`422`. Only an empty group can be deleted. This one still has members or an active sub-group.

**Fix:** Remove its members and sub-group links, then delete it.

### automatic_category_read_only

`422`. The Automatic group category is managed by Tayl.

**Fix:** Use another category.

### category_not_deletable

`422`. A group category with groups attached can't be deleted.

**Fix:** Move or delete its groups first.

## Assignments

### content_not_available

`422`. No published course, pathway or document with that ID is available to the organisation.

**Fix:** Find assignable content with `GET /api/v1/courses`, `/pathways` or `/signable-documents`.

### content_not_in_library

`422`. The content is one of Tayl's courses that the organisation hasn't added to its content library.

**Fix:** An admin or content manager adds it to the content library in Tayl, then assign it.

### unresolvable_target

`422`. A target didn't match a person or group the key can assign training to. `pointer` says which one. A manager's personal key can assign only to people and groups they manage and cannot directly target an admin.

**Fix:** Check the target's ID or `external_id`, and that it's in the key's reach.

### assignment_archived

`422`. An archived assignment can't be changed.

**Fix:** Create a new assignment instead.

### assignment_frozen

`422`. The assignment's targets can't change while it's frozen.

**Fix:** Leave its targets as they are, or create a new assignment.

### not_publishable

`422`. The assignment or course can't be published yet. For an assignment, another published assignment may already cover the same content and people, or no targets remain. For a course, the message says what's missing, as the course builder would.

**Fix:** Fix what the message describes. For a course, `publishable` and `publish_error` on each read show whether it's ready.

## Course authoring

### no_draft

`404`. The course is published and has no draft to read or change.

**Fix:** Start one with `POST /api/v1/courses/{id}/draft`, then read and change the draft.

### precondition_required

`428`. A course write needs the `etag` from your last read.

**Fix:** Send it as the `If-Match` header.

### version_changed

`412`. The course changed after you read it, perhaps in the course builder, so your `If-Match` etag is out of date.

**Fix:** Read the draft again, reapply your changes, and send them with the new `etag`.

### course_archived

`422`. An archived course can't be changed.

**Fix:** Unarchive it with `POST /api/v1/courses/{id}/unarchive` first.

### course_synced_from_v2

`422`. The Tayl course still syncs from Taylv2, which sets this setting, so the next sync would undo a change made here.

**Fix:** Change it in Taylv2. Once the course is edited here, it stops syncing for good and the setting can be changed.

### invalid_patch

`422`. The JSON Patch couldn't be applied, for example a path that doesn't exist or a failed `test` operation.

**Fix:** Read the document again and build the patch from its current paths.

### document_too_large

`422`. The course, chapter or page document is over the limits of 100,000 values, 15,000 records or 10 MB.

**Fix:** Save it a chapter or page at a time instead.

### not_deletable

`422`. Only a course that has never been published can be deleted.

**Fix:** Archive it instead with `POST /api/v1/courses/{id}/archive`.

### not_discardable

`422`. There's no draft to discard. A course that has never been published is all draft.

**Fix:** Delete a never-published course with `DELETE /api/v1/courses/{id}` instead.

### not_archivable

`422`. Only a published course can be archived.

**Fix:** Check the course's `status` first.

### not_unarchivable

`422`. Only an archived course can be unarchived.

**Fix:** Check the course's `status` first.

## Webhooks and certificates

### endpoint_deactivated

`422`. The delivery's webhook endpoint is deactivated, so it can't be retried.

**Fix:** Reactivate the endpoint with `POST /api/v1/webhook-endpoints/{id}/reactivate`, then retry.

### event_unsubscribed

`422`. The endpoint no longer subscribes to the delivery's event.

**Fix:** Add the event back to the endpoint, then retry.

### delivery_not_retryable

`422`. Only failed or abandoned deliveries can be retried.

**Fix:** Check the delivery's `status` first.

### certificate_generation_failed

`503`. The certificate's PDF couldn't be generated this time.

**Fix:** Retry later with bounded backoff.
