---
title: "Search flaky tests"
method: POST
path: "/api/v2/test/flaky-test-management/tests"
tags: ["Test Optimization"]
---

# Search flaky tests

`POST /api/v2/test/flaky-test-management/tests`

List endpoint returning flaky tests from Flaky Test Management. Results are paginated.

The response includes comprehensive test information including:
- Test identification and metadata (module, suite, name)
- Flaky state and categorization
- First and last flake occurrences (timestamp, branch, commit SHA)
- Test execution statistics from the last 7 days (failure rate)
- Pipeline impact metrics (failed pipelines count, total lost time)
- Complete status change history (optional, ordered from most recent to oldest)

Set `include_history` to `true` in the request to receive the status change history for each test.
History is disabled by default for better performance.

Results support filtering by various facets including service, environment, repository, branch, and test state.

## Request body

- FlakyTestsSearchRequest — The request for a flaky tests search.
  - `data` FlakyTestsSearchRequestData — The JSON:API data for flaky tests search request.
    - `attributes` FlakyTestsSearchRequestAttributes — Attributes for the flaky tests search request.
      - `filter` FlakyTestsSearchFilter — Search filter settings.
        - `include_history` boolean — Whether to include the status change history for each flaky test in the response. When set to true, each test will include a `history` array with chronological status changes. Defaults to false.
        - `query` string — Search query following log syntax used to filter flaky tests, same as on Flaky Tests Management UI. The supported search keys are: - `flaky_test_state` - `flaky_test_category` - `@test.name` - `@test.suite` - `@test.module` - `@test.service` - `@git.repository.id_v2` - `@git.branch` - `@test.codeowners` - `env` - `fingerprint_fqn` Use `fingerprint_fqn` to filter by a test's stable Fingerprint FQN (the same value as the test's `id`).
      - `page` FlakyTestsSearchPageOptions — Pagination attributes for listing flaky tests.
        - `cursor` string — List following results with a cursor provided in the previous request.
        - `limit` integer — Maximum number of flaky tests in the response.
      - `sort` 'fqn' | '-fqn' | 'first_flaked' | '-first_flaked' | 'last_flaked' | '-last_flaked' | 'failure_rate' | '-failure_rate' | 'pipelines_failed' | '-pipelines_failed' | 'pipelines_duration_lost' | '-pipelines_duration_lost' — Parameter for sorting flaky test results. The default sort is by ascending Fully Qualified Name (FQN). The FQN is the concatenation of the test module, suite, and name.
    - `type` 'search_flaky_tests_request' — The definition of `FlakyTestsSearchRequestDataType` object.

## Response `200`

OK

- FlakyTestsSearchResponse — Response object with flaky tests matching the search request.
  - `data` FlakyTest[] — Array of flaky tests matching the request.
    - `attributes` FlakyTestAttributes — Attributes of a flaky test.
      - `attempt_to_fix_id` string — Unique identifier for the attempt to fix this flaky test. Use this ID in the Git commit message in order to trigger the attempt to fix workflow. When the workflow is triggered the test is automatically retried by the tracer a certain number of configurable times. When all retries pass, the test is automatically marked as fixed in Flaky Test Management. Test runs are tagged with @test.test_management.attempt_to_fix_passed and @test.test_management.is_attempt_to_fix when the attempt to fix workflow is triggered.
      - `codeowners` string[] — The name of the test's code owners as inferred from the repository configuration.
      - `envs` string[] — List of environments where this test has been flaky.
      - `first_flaked_branch` string — The branch name where the test exhibited flakiness for the first time.
      - `first_flaked_sha` string — The commit SHA where the test exhibited flakiness for the first time.
      - `first_flaked_ts` integer — Unix timestamp when the test exhibited flakiness for the first time.
      - `flaky_category` string, nullable — The category of a flaky test.
      - `flaky_state` 'active' | 'fixed' | 'quarantined' | 'disabled' — The current state of the flaky test.
      - `history` FlakyTestHistory[] — Chronological history of status changes for this flaky test, ordered from most recent to oldest. Includes state transitions like new -> quarantined -> fixed, along with the associated commit SHA when available.
        - `commit_sha` string, required — The commit SHA associated with this status change. Will be an empty string if the commit SHA is not available.
        - `policy_id` 'ftm_policy.manual' | 'ftm_policy.fixed' | 'ftm_policy.disable.failure_rate' | 'ftm_policy.disable.branch_flake' | 'ftm_policy.disable.days_active' | 'ftm_policy.quarantine.failure_rate' | 'ftm_policy.quarantine.branch_flake' | 'ftm_policy.quarantine.days_active' | 'unknown' — The policy that triggered this status change.
        - `policy_meta` FlakyTestHistoryPolicyMeta — Metadata about the policy that triggered this status change.
          - `branches` string[], nullable — Branches where the test was flaky at the time of the status change.
          - `config` FlakyTestHistoryPolicyMetaConfig — Configuration parameters of the policy that triggered this status change.
            - `branches` string[], nullable — The branches considered by the policy.
            - `days_active` integer, nullable — The number of days a test must have been active for the policy to trigger.
            - `failure_rate` number, double, nullable — The failure rate threshold for the policy to trigger.
            - `forget_branches` string[], nullable — Branches excluded from the policy evaluation.
            - `required_runs` integer, nullable — The minimum number of test runs required for the policy to trigger.
            - `state` string, nullable — The target state the policy transitions the test from.
            - `test_services` string[], nullable — Test services excluded from the policy evaluation.
          - `days_active` integer, nullable — The number of days the test has been active at the time of the status change.
          - `days_without_flake` integer, nullable — The number of days since the test last exhibited flakiness.
          - `failure_rate` number, double, nullable — The failure rate of the test at the time of the status change.
          - `state` string, nullable — The previous state of the test.
          - `total_runs` integer, nullable — The total number of test runs at the time of the status change.
        - `status` string, required — The test status at this point in history.
        - `timestamp` integer, required — Unix timestamp in milliseconds when this status change occurred.
      - `last_flaked_branch` string — The branch name where the test exhibited flakiness for the last time.
      - `last_flaked_sha` string — The commit SHA where the test exhibited flakiness for the last time.
      - `last_flaked_ts` integer — Unix timestamp when the test exhibited flakiness for the last time.
      - `module` string, nullable — The name of the test module. The definition of module changes slightly per language: - In .NET, a test module groups every test that is run under the same unit test project. - In Swift, a test module groups every test that is run for a given bundle. - In JavaScript, the test modules map one-to-one to test sessions. - In Java, a test module groups every test that is run by the same Maven Surefire/Failsafe or Gradle Test task execution. - In Python, a test module groups every test that is run under the same `.py` file as part of a test suite, which is typically managed by a framework like `unittest` or `pytest`. - In Ruby, a test module groups every test that is run within the same test file, which is typically managed by a framework like `RSpec` or `Minitest`.
      - `name` string — The test name. A concise name for a test case. Defined in the test itself.
      - `pipeline_stats` FlakyTestPipelineStats — CI pipeline related statistics for the flaky test. This information is only available if test runs are associated with CI pipeline events from CI Visibility.
        - `failed_pipelines` integer, nullable — The number of pipelines that failed due to this test for the past 7 days. This is computed as the sum of failed CI pipeline events associated with test runs where the flaky test failed.
        - `total_lost_time_ms` integer, nullable — The total time lost by CI pipelines due to this flaky test in milliseconds. This is computed as the sum of the duration of failed CI pipeline events associated with test runs where the flaky test failed.
      - `services` string[] — List of test service names where this test has been flaky. A test service is a group of tests associated with a project or repository. It contains all the individual tests for your code, optionally organized into test suites, which are like folders for your tests.
      - `suite` string — The name of the test suite. A group of tests exercising the same unit of code depending on your language and testing framework.
      - `test_run_metadata` FlakyTestRunMetadata — Metadata about the latest failed test run of the flaky test.
        - `duration_ms` integer, nullable — The duration of the test run in milliseconds.
        - `error_message` string, nullable — The error message from the test failure.
        - `error_stack` string, nullable — The stack trace from the test failure.
        - `source_end` integer, nullable — The line number where the test ends in the source file.
        - `source_file` string, nullable — The source file where the test is defined.
        - `source_start` integer, nullable — The line number where the test starts in the source file.
      - `test_stats` FlakyTestStats — Test statistics for the flaky test.
        - `failure_rate_pct` number, double, nullable — The failure rate percentage of the test for the past 7 days. This is the number of failed test runs divided by the total number of test runs (excluding skipped test runs).
    - `id` string — Test's ID. This ID is the hash of the test's Fully Qualified Name and Git repository ID. It is the value of the `@test.fingerprint_fqn` facet on test events, which you can search on in the Test Optimization Explorer to locate a specific test. To filter search results by this ID, use the `fingerprint_fqn` search key.
    - `type` 'flaky_test' — The type of the flaky test from Flaky Test Management.
  - `meta` FlakyTestsSearchResponseMeta — Metadata for the flaky tests search response.
    - `pagination` FlakyTestsPagination — Pagination metadata for flaky tests.
      - `next_page` string, nullable — Cursor for the next page of results.

## Other responses

- `400` — Bad Request
- `403` — Not Authorized
- `429` — Too many requests

---

[API](https://skmtc.net/datadog/apis/api-v2.md) · [All operations](https://skmtc.net/datadog/apis/api-v2/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/datadog/api-v2/revisions/da68bf029e4c/schema)
