---
title: Update resource filters
description: Update resource filters.
breadcrumbs: Docs > API > Update resource filters
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/llms.txt).

# Update resource filters

## v2 (latest)

| Datadog site      | API endpoint                                                                        |
| ----------------- | ----------------------------------------------------------------------------------- |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/cloud_security_management/resource_filters     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/cloud_security_management/resource_filters |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/cloud_security_management/resource_filters |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/cloud_security_management/resource_filters      |
| ap1.datadoghq.com | PUT https://api.ap1.datadoghq.com/api/v2/cloud_security_management/resource_filters |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/cloud_security_management/resource_filters |
| uk1.datadoghq.com | PUT https://api.uk1.datadoghq.com/api/v2/cloud_security_management/resource_filters |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/cloud_security_management/resource_filters      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/cloud_security_management/resource_filters  |

### Overview

Update resource filters.

This endpoint requires the `security_monitoring_filters_write` permission.

OAuth apps require the `security_monitoring_filters_write` authorization [scope](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/api/latest/scopes.md#security-monitoring) to access this endpoint.

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field         | Field                       | Type     | Description                                                                                                                    |
| -------------------- | --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
|                      | data [*required*]           | object   | The definition of `UpdateResourceFilterRequestData` object.                                                                    |
| data                 | attributes [*required*]     | object   | Attributes of a resource filter.                                                                                               |
| attributes           | cloud_provider [*required*] | object   | A map of cloud provider names (e.g., "aws", "gcp", "azure") to a map of account/resource IDs and their associated tag filters. |
| additionalProperties | <any-key>                   | object   |                                                                                                                                |
| additionalProperties | <any-key>                   | [string] |                                                                                                                                |
| attributes           | uuid                        | string   | The UUID of the resource filter.                                                                                               |
| data                 | id                          | string   | The `UpdateResourceEvaluationFiltersRequestData` `id`.                                                                         |
| data                 | type [*required*]           | enum     | Constant string to identify the request type. Allowed enum values: `csm_resource_filter`.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "cloud_provider": {
        "aws": {
          "aws_account_id": [
            "tag1:v1"
          ]
        }
      }
    },
    "id": "csm_resource_filter",
    "type": "csm_resource_filter"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="201" %}
OK

{% tabs %}
{% tab label="Model" %}
The definition of `UpdateResourceEvaluationFiltersResponse` object.

| Parent field         | Field                       | Type     | Description                                                                                                                    |
| -------------------- | --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
|                      | data [*required*]           | object   | The definition of `UpdateResourceFilterResponseData` object.                                                                   |
| data                 | attributes [*required*]     | object   | Attributes of a resource filter.                                                                                               |
| attributes           | cloud_provider [*required*] | object   | A map of cloud provider names (e.g., "aws", "gcp", "azure") to a map of account/resource IDs and their associated tag filters. |
| additionalProperties | <any-key>                   | object   |                                                                                                                                |
| additionalProperties | <any-key>                   | [string] |                                                                                                                                |
| attributes           | uuid                        | string   | The UUID of the resource filter.                                                                                               |
| data                 | id                          | string   | The `data` `id`.                                                                                                               |
| data                 | type [*required*]           | enum     | Constant string to identify the request type. Allowed enum values: `csm_resource_filter`.                                      |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "cloud_provider": {
        "<any-key>": {
          "<any-key>": [
            "environment:production"
          ]
        }
      },
      "uuid": "string"
    },
    "id": "csm_resource_filter",
    "type": "csm_resource_filter"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Not Authorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X PUT "https://api.${DD_SITE}/api/v2/cloud_security_management/resource_filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "cloud_provider": {
        "aws": {
          "aws_account_id": [
            "tag1:v1"
          ]
        }
      }
    },
    "id": "csm_resource_filter",
    "type": "csm_resource_filter"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Update resource filters 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.UpdateResourceEvaluationFiltersRequest{
		Data: datadogV2.UpdateResourceEvaluationFiltersRequestData{
			Attributes: datadogV2.ResourceFilterAttributes{
				CloudProvider: map[string]map[string][]string{
					"aws": map[string][]string{
						"aws_account_id": []string{
							"tag1:v1",
						},
					},
				},
			},
			Id:   datadog.PtrString("csm_resource_filter"),
			Type: datadogV2.RESOURCEFILTERREQUESTTYPE_CSM_RESOURCE_FILTER,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewSecurityMonitoringApi(apiClient)
	resp, r, err := api.UpdateResourceEvaluationFilters(ctx, body)

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

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

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Update resource filters returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.SecurityMonitoringApi;
import com.datadog.api.client.v2.model.ResourceFilterAttributes;
import com.datadog.api.client.v2.model.ResourceFilterRequestType;
import com.datadog.api.client.v2.model.UpdateResourceEvaluationFiltersRequest;
import com.datadog.api.client.v2.model.UpdateResourceEvaluationFiltersRequestData;
import com.datadog.api.client.v2.model.UpdateResourceEvaluationFiltersResponse;
import java.util.Collections;
import java.util.Map;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    SecurityMonitoringApi apiInstance = new SecurityMonitoringApi(defaultClient);

    UpdateResourceEvaluationFiltersRequest body =
        new UpdateResourceEvaluationFiltersRequest()
            .data(
                new UpdateResourceEvaluationFiltersRequestData()
                    .attributes(
                        new ResourceFilterAttributes()
                            .cloudProvider(
                                Map.ofEntries(
                                    Map.entry(
                                        "aws",
                                        Map.ofEntries(
                                            Map.entry(
                                                "aws_account_id",
                                                Collections.singletonList("tag1:v1")))))))
                    .id("csm_resource_filter")
                    .type(ResourceFilterRequestType.CSM_RESOURCE_FILTER));

    try {
      UpdateResourceEvaluationFiltersResponse result =
          apiInstance.updateResourceEvaluationFilters(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling SecurityMonitoringApi#updateResourceEvaluationFilters");
      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://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Update resource filters returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.security_monitoring_api import SecurityMonitoringApi
from datadog_api_client.v2.model.resource_filter_attributes import ResourceFilterAttributes
from datadog_api_client.v2.model.resource_filter_request_type import ResourceFilterRequestType
from datadog_api_client.v2.model.update_resource_evaluation_filters_request import (
    UpdateResourceEvaluationFiltersRequest,
)
from datadog_api_client.v2.model.update_resource_evaluation_filters_request_data import (
    UpdateResourceEvaluationFiltersRequestData,
)

body = UpdateResourceEvaluationFiltersRequest(
    data=UpdateResourceEvaluationFiltersRequestData(
        attributes=ResourceFilterAttributes(
            cloud_provider=dict(
                aws=dict(
                    aws_account_id=[
                        "tag1:v1",
                    ],
                ),
            ),
        ),
        id="csm_resource_filter",
        type=ResourceFilterRequestType.CSM_RESOURCE_FILTER,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
    api_instance = SecurityMonitoringApi(api_client)
    response = api_instance.update_resource_evaluation_filters(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Update resource filters returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::SecurityMonitoringAPI.new

body = DatadogAPIClient::V2::UpdateResourceEvaluationFiltersRequest.new({
  data: DatadogAPIClient::V2::UpdateResourceEvaluationFiltersRequestData.new({
    attributes: DatadogAPIClient::V2::ResourceFilterAttributes.new({
      cloud_provider: {
        aws: {
          aws_account_id: [
            "tag1:v1",
          ],
        },
      },
    }),
    id: "csm_resource_filter",
    type: DatadogAPIClient::V2::ResourceFilterRequestType::CSM_RESOURCE_FILTER,
  }),
})
p api_instance.update_resource_evaluation_filters(body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Update resource filters returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_security_monitoring::SecurityMonitoringAPI;
use datadog_api_client::datadogV2::model::ResourceFilterAttributes;
use datadog_api_client::datadogV2::model::ResourceFilterRequestType;
use datadog_api_client::datadogV2::model::UpdateResourceEvaluationFiltersRequest;
use datadog_api_client::datadogV2::model::UpdateResourceEvaluationFiltersRequestData;
use std::collections::BTreeMap;

#[tokio::main]
async fn main() {
    let body = UpdateResourceEvaluationFiltersRequest::new(
        UpdateResourceEvaluationFiltersRequestData::new(
            ResourceFilterAttributes::new(BTreeMap::from([(
                "aws".to_string(),
                BTreeMap::from([("aws_account_id".to_string(), vec!["tag1:v1".to_string()])]),
            )])),
            ResourceFilterRequestType::CSM_RESOURCE_FILTER,
        )
        .id("csm_resource_filter".to_string()),
    );
    let configuration = datadog::Configuration::new();
    let api = SecurityMonitoringAPI::with_config(configuration);
    let resp = api.update_resource_evaluation_filters(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Update resource filters returns "OK" response
 */

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

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
const apiInstance = new v2.SecurityMonitoringApi(configuration);

const params: v2.SecurityMonitoringApiUpdateResourceEvaluationFiltersRequest = {
  body: {
    data: {
      attributes: {
        cloudProvider: {
          aws: {
            aws_account_id: ["tag1:v1"],
          },
        },
      },
      id: "csm_resource_filter",
      type: "csm_resource_filter",
    },
  },
};

apiInstance
  .updateResourceEvaluationFilters(params)
  .then((data: v2.UpdateResourceEvaluationFiltersResponse) => {
    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://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
