> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trunk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate Flaky Tests from the legacy API

> The legacy repository-scoped Flaky Tests endpoints are retired. Use the test collection endpoints instead.

The legacy Flaky Tests endpoints (`/v1/flaky-tests/*`) were scoped to a repository, and they are retired along with repository-scoped Flaky Tests. They still accept requests but no longer return results. Use the API's [test collection](https://docs.trunk.io/flaky-tests/test-collections.md) endpoints instead.

The two scopes are separate APIs, not two versions of one API. So not every legacy endpoint has an equivalent with the same shape.

## What changes

* **Credential.** The legacy API uses the organization API token in `x-api-token`. The API uses an [API key](https://docs.trunk.io/api/authentication#api-keys) in `Authorization: Bearer <key>`. Any API key can call the Flaky Tests endpoints. They need no [permission](https://docs.trunk.io/api/authentication#permissions).
* **Base URL.** Legacy paths go after `https://api.trunk.io/v1`. API paths already start with `/v2`, so they go after `https://api.trunk.io`.
* **Method.** Legacy endpoints are `POST` with a JSON body. API reads are `GET` with query parameters.
* **Lists.** API lists are [paginated](https://docs.trunk.io/api/pagination.md) with cursors.
* **Errors.** API errors use the [error envelope](https://docs.trunk.io/api/errors.md#error-envelope). Switch on `error.code`.

## Endpoint map

| If you want to | Retired legacy endpoint | Endpoint to use |
| - | - | - |
| Read one test | `POST /flaky-tests/get-test-details` | [Get a test](https://docs.trunk.io/api/tests/get-a-test.md) |
| Find unhealthy tests | `POST /flaky-tests/list-unhealthy-tests` | [List and search tests](https://docs.trunk.io/api/tests/list-and-search-tests.md), filtered by status |
| Find quarantined tests | `POST /flaky-tests/list-quarantined-tests` | [List and search tests](https://docs.trunk.io/api/tests/list-and-search-tests.md), filtered by quarantine state |
| Find recent failures | `POST /flaky-tests/list-failing-tests` | [List a test's runs](https://docs.trunk.io/api/tests/list-a-tests-runs.md) |
| Link a ticket to a test | `POST /flaky-tests/link-ticket-to-test-case` | [Link a ticket to a test](https://docs.trunk.io/api/tests/link-a-ticket-to-a-test.md) |
| File a new ticket for a test | *Not applicable* | [Create a ticket for a test](https://docs.trunk.io/api/tests/create-a-ticket-for-a-test.md) |
| List or create collections | *Not applicable* | [List](https://docs.trunk.io/api/testcollections/list-test-collections.md) / [Create a test collection](https://docs.trunk.io/api/testcollections/create-a-test-collection.md) |

> [!NOTE]
>
> A test's ID in a collection is not the ID the legacy endpoints returned, so an ID stored from a legacy endpoint can't be passed to a collection endpoint. The repository's `repository.id` is the only identifier the two share.

Tools that don't accept API keys yet, including the Trunk Analytics CLI, `trunk-io/analytics-uploader`, and the Trunk MCP server's token sign-in, still need the organization API token.
