---
title: Update flaky test states
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Test Optimization
---

# Update flaky test states{% #update-flaky-test-states %}

{% tab title="v2" %}

| Datadog site      | API endpoint                                                                |
| ----------------- | --------------------------------------------------------------------------- |
| ap1.datadoghq.com | PATCH https://api.ap1.datadoghq.com/api/v2/test/flaky-test-management/tests |
| ap2.datadoghq.com | PATCH https://api.ap2.datadoghq.com/api/v2/test/flaky-test-management/tests |
| app.datadoghq.eu  | PATCH https://api.datadoghq.eu/api/v2/test/flaky-test-management/tests      |
| app.ddog-gov.com  | PATCH https://api.ddog-gov.com/api/v2/test/flaky-test-management/tests      |
| us2.ddog-gov.com  | PATCH https://api.us2.ddog-gov.com/api/v2/test/flaky-test-management/tests  |
| app.datadoghq.com | PATCH https://api.datadoghq.com/api/v2/test/flaky-test-management/tests     |
| us3.datadoghq.com | PATCH https://api.us3.datadoghq.com/api/v2/test/flaky-test-management/tests |
| us5.datadoghq.com | PATCH https://api.us5.datadoghq.com/api/v2/test/flaky-test-management/tests |

### Overview

Update the state of multiple flaky tests in Flaky Test Management. This endpoint requires the `test_optimization_write` permission.

OAuth apps require the `test_optimization_write` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#test-optimization) to access this endpoint.



### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                        | Type     | Description                                                                                                                                                     |
| ------------ | ---------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data [*required*]       | object   | The JSON:API data for updating flaky test states.                                                                                                               |
| data         | attributes [*required*] | object   | Attributes for updating flaky test states.                                                                                                                      |
| attributes   | tests [*required*]      | [object] | List of flaky tests to update.                                                                                                                                  |
| tests        | id [*required*]         | string   | The ID of the flaky test. This is the same ID returned by the Search flaky tests endpoint and corresponds to the test_fingerprint_fqn field in test run events. |
| tests        | new_state [*required*]  | enum     | The new state to set for the flaky test. Allowed enum values: `active,quarantined,disabled,fixed`                                                               |
| data         | type [*required*]       | enum     | The definition of `UpdateFlakyTestsRequestDataType` object. Allowed enum values: `update_flaky_test_state_request`                                              |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "tests": [
        {
          "id": "4eb1887a8adb1847",
          "new_state": "active"
        }
      ]
    },
    "type": "update_flaky_test_state_request"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response object for updating flaky test states.

| Parent field | Field                        | Type     | Description                                                                                                                                                                      |
| ------------ | ---------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|              | data                         | object   | Summary of the update operations. Tells whether a test succeeded or failed to be updated.                                                                                        |
| data         | attributes                   | object   | Attributes for the update flaky test state response.                                                                                                                             |
| attributes   | has_errors [*required*] | boolean  | `True` if any errors occurred during the update operations. `False` if all tests succeeded to be updated.                                                                        |
| attributes   | results [*required*]    | [object] | Results of the update operation for each test.                                                                                                                                   |
| results      | error                        | string   | Error message if the update failed.                                                                                                                                              |
| results      | id [*required*]         | string   | The ID of the flaky test from the request. This is the same ID returned by the Search flaky tests endpoint and corresponds to the test_fingerprint_fqn field in test run events. |
| results      | success [*required*]    | boolean  | `True` if the update was successful, `False` if there were any errors.                                                                                                           |
| data         | id                           | string   | The ID of the response.                                                                                                                                                          |
| data         | type                         | enum     | The definition of `UpdateFlakyTestsResponseDataType` object. Allowed enum values: `update_flaky_test_state_response`                                                             |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "has_errors": true,
      "results": [
        {
          "error": "string",
          "id": "4eb1887a8adb1847",
          "success": false
        }
      ]
    },
    "id": "string",
    "type": "string"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Not Authorized
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X PATCH "https://api.datadoghq.com/api/v2/test/flaky-test-management/tests" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "tests": [
        {
          "id": "4eb1887a8adb1847",
          "new_state": "active"
        }
      ]
    },
    "type": "update_flaky_test_state_request"
  }
}
EOF 
                
##### 

```python
"""
Update flaky test states returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.test_optimization_api import TestOptimizationApi
from datadog_api_client.v2.model.update_flaky_tests_request import UpdateFlakyTestsRequest
from datadog_api_client.v2.model.update_flaky_tests_request_attributes import UpdateFlakyTestsRequestAttributes
from datadog_api_client.v2.model.update_flaky_tests_request_data import UpdateFlakyTestsRequestData
from datadog_api_client.v2.model.update_flaky_tests_request_data_type import UpdateFlakyTestsRequestDataType
from datadog_api_client.v2.model.update_flaky_tests_request_test import UpdateFlakyTestsRequestTest
from datadog_api_client.v2.model.update_flaky_tests_request_test_new_state import UpdateFlakyTestsRequestTestNewState

body = UpdateFlakyTestsRequest(
    data=UpdateFlakyTestsRequestData(
        attributes=UpdateFlakyTestsRequestAttributes(
            tests=[
                UpdateFlakyTestsRequestTest(
                    id="4eb1887a8adb1847",
                    new_state=UpdateFlakyTestsRequestTestNewState.ACTIVE,
                ),
            ],
        ),
        type=UpdateFlakyTestsRequestDataType.UPDATE_FLAKY_TEST_STATE_REQUEST,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = TestOptimizationApi(api_client)
    response = api_instance.update_flaky_tests(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
# Update flaky test states returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::TestOptimizationAPI.new

body = DatadogAPIClient::V2::UpdateFlakyTestsRequest.new({
  data: DatadogAPIClient::V2::UpdateFlakyTestsRequestData.new({
    attributes: DatadogAPIClient::V2::UpdateFlakyTestsRequestAttributes.new({
      tests: [
        DatadogAPIClient::V2::UpdateFlakyTestsRequestTest.new({
          id: "4eb1887a8adb1847",
          new_state: DatadogAPIClient::V2::UpdateFlakyTestsRequestTestNewState::ACTIVE,
        }),
      ],
    }),
    type: DatadogAPIClient::V2::UpdateFlakyTestsRequestDataType::UPDATE_FLAKY_TEST_STATE_REQUEST,
  }),
})
p api_instance.update_flaky_tests(body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```go
// Update flaky test states returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.UpdateFlakyTestsRequest{
		Data: datadogV2.UpdateFlakyTestsRequestData{
			Attributes: datadogV2.UpdateFlakyTestsRequestAttributes{
				Tests: []datadogV2.UpdateFlakyTestsRequestTest{
					{
						Id:       "4eb1887a8adb1847",
						NewState: datadogV2.UPDATEFLAKYTESTSREQUESTTESTNEWSTATE_ACTIVE,
					},
				},
			},
			Type: datadogV2.UPDATEFLAKYTESTSREQUESTDATATYPE_UPDATE_FLAKY_TEST_STATE_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewTestOptimizationApi(apiClient)
	resp, r, err := api.UpdateFlakyTests(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `TestOptimizationApi.UpdateFlakyTests`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `TestOptimizationApi.UpdateFlakyTests`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Update flaky test states returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.TestOptimizationApi;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequest;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestAttributes;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestData;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestDataType;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestTest;
import com.datadog.api.client.v2.model.UpdateFlakyTestsRequestTestNewState;
import com.datadog.api.client.v2.model.UpdateFlakyTestsResponse;
import java.util.Collections;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    TestOptimizationApi apiInstance = new TestOptimizationApi(defaultClient);

    UpdateFlakyTestsRequest body =
        new UpdateFlakyTestsRequest()
            .data(
                new UpdateFlakyTestsRequestData()
                    .attributes(
                        new UpdateFlakyTestsRequestAttributes()
                            .tests(
                                Collections.singletonList(
                                    new UpdateFlakyTestsRequestTest()
                                        .id("4eb1887a8adb1847")
                                        .newState(UpdateFlakyTestsRequestTestNewState.ACTIVE))))
                    .type(UpdateFlakyTestsRequestDataType.UPDATE_FLAKY_TEST_STATE_REQUEST));

    try {
      UpdateFlakyTestsResponse result = apiInstance.updateFlakyTests(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling TestOptimizationApi#updateFlakyTests");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```rust
// Update flaky test states returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_test_optimization::TestOptimizationAPI;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequest;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestAttributes;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestData;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestDataType;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestTest;
use datadog_api_client::datadogV2::model::UpdateFlakyTestsRequestTestNewState;

#[tokio::main]
async fn main() {
    let body = UpdateFlakyTestsRequest::new(UpdateFlakyTestsRequestData::new(
        UpdateFlakyTestsRequestAttributes::new(vec![UpdateFlakyTestsRequestTest::new(
            "4eb1887a8adb1847".to_string(),
            UpdateFlakyTestsRequestTestNewState::ACTIVE,
        )]),
        UpdateFlakyTestsRequestDataType::UPDATE_FLAKY_TEST_STATE_REQUEST,
    ));
    let configuration = datadog::Configuration::new();
    let api = TestOptimizationAPI::with_config(configuration);
    let resp = api.update_flaky_tests(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Update flaky test states returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.TestOptimizationApi(configuration);

const params: v2.TestOptimizationApiUpdateFlakyTestsRequest = {
  body: {
    data: {
      attributes: {
        tests: [
          {
            id: "4eb1887a8adb1847",
            newState: "active",
          },
        ],
      },
      type: "update_flaky_test_state_request",
    },
  },
};

apiInstance
  .updateFlakyTests(params)
  .then((data: v2.UpdateFlakyTestsResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
