> ## 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

> Move Flaky Tests integrations from the v1 repository endpoints to the v2 test collection endpoints.

The Flaky Tests v1 endpoints are scoped to a repository. The v2 endpoints are scoped to a [test collection](https://docs.trunk.io/flaky-tests/test-collections.md). If your tests are still organized by repository, first [move them into test collections](https://docs.trunk.io/flaky-tests/get-started/migrate-to-test-collections.md).

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

## What changes

* **Credential.** v1 uses the organization API token in `x-api-token`. v2 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.** v1 paths go after `https://api.trunk.io/v1`. v2 paths already start with `/v2`, so they go after `https://api.trunk.io`.
* **Method.** v1 endpoints are `POST` with a JSON body. v2 reads are `GET` with query parameters.
* **Lists.** v2 lists are [paginated](https://docs.trunk.io/api/pagination.md) with cursors.
* **Errors.** v2 errors use the [error envelope](https://docs.trunk.io/api/errors.md#error-envelope). Switch on `error.code`.

## Endpoint map

| If you want to | Repository endpoint | Collection endpoint |
| - | - | - |
| Read one test | [Get the details of a test case](https://docs.trunk.io/api/v1/get-the-details-of-a-test-case.md) | [Get a test](https://docs.trunk.io/api/tests/get-a-test.md) |
| Find unhealthy tests | [Get a list of unhealthy tests](https://docs.trunk.io/api/v1/get-a-list-of-unhealthy-tests.md) | [List and search tests](https://docs.trunk.io/api/tests/list-and-search-tests.md), filtered by status |
| Find quarantined tests | [Get a list of quarantined tests](https://docs.trunk.io/api/v1/get-a-list-of-quarantined-tests.md) | [List and search tests](https://docs.trunk.io/api/tests/list-and-search-tests.md), filtered by quarantine state |
| Find recent failures | [Get a list of distinct tests that failed](https://docs.trunk.io/api/v1/get-a-list-of-distinct-tests-that-failed-in-the-given-time-range.md) | [List a test's runs](https://docs.trunk.io/api/tests/list-a-tests-runs.md) |
| Link a ticket to a test | [Link a ticket to a test case](https://docs.trunk.io/api/v1/link-a-ticket-to-a-test-case.md) | [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 is not the same value in both scopes, so an ID read from a repository endpoint can't be passed to a collection endpoint or vice versa. 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.
