---
title: Creates a data deletion request
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Data Deletion
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Creates a data deletion request{% #creates-a-data-deletion-request %}
Copy pageCopied
{% tab title="v2" %}

| Datadog site      | API endpoint                                                      |
| ----------------- | ----------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/deletion/data/{product} |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/deletion/data/{product} |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/deletion/data/{product}      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/deletion/data/{product}      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/deletion/data/{product}  |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/deletion/data/{product} |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/deletion/data/{product}     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/deletion/data/{product} |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/deletion/data/{product} |

### Overview

Creates a data deletion request by providing a query and a timeframe targeting the proper data. This endpoint requires the `logs_delete_data` permission.

### Arguments

#### Path Parameters

| Name                      | Type   | Description                                                  |
| ------------------------- | ------ | ------------------------------------------------------------ |
| product [*required*] | string | Name of the product to be deleted. Only `logs` is supported. |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field         | Field                             | Type     | Description                                                                              |
| -------------------- | --------------------------------- | -------- | ---------------------------------------------------------------------------------------- |
|                      | data [*required*]            | object   | Data needed to create a data deletion request.                                           |
| data                 | attributes [*required*]      | object   | Attributes for creating a data deletion request.                                         |
| attributes           | displayed_total [*required*] | int64    | Total number of elements to be deleted as displayed to the user.                         |
| attributes           | from [*required*]            | int64    | Start of requested time window, milliseconds since Unix epoch.                           |
| attributes           | indexes                           | [string] | List of indexes for the search. If not provided, the search is performed in all indexes. |
| attributes           | query [*required*]           | object   | Query for creating a data deletion request.                                              |
| additionalProperties | <any-key>                         | string   |
| attributes           | to [*required*]              | int64    | End of requested time window, milliseconds since Unix epoch.                             |
| data                 | type [*required*]            | enum     | The deletion request type. Allowed enum values: `create_deletion_req`                    |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "displayed_total": 100,
      "from": 1672527600000,
      "indexes": [
        "test-index",
        "test-index-2"
      ],
      "query": {
        "host": "abc",
        "service": "xyz"
      },
      "to": 1704063600000
    },
    "type": "create_deletion_req"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
The response from the create data deletion request endpoint.

| Parent field         | Field                                | Type     | Description                                                                                                                                                       |
| -------------------- | ------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data                                 | object   | The created data deletion request information.                                                                                                                    |
| data                 | attributes [*required*]         | object   | Deletion attribute for data deletion response.                                                                                                                    |
| attributes           | created_at [*required*]         | string   | Creation time of the deletion request.                                                                                                                            |
| attributes           | created_by [*required*]         | string   | User who created the deletion request.                                                                                                                            |
| attributes           | customer_message                     | string   | A message for the customer regarding the deletion request, if any.                                                                                                |
| attributes           | displayed_total [*required*]    | int64    | Total number of elements to be deleted as displayed to the user.                                                                                                  |
| attributes           | error_category                       | string   | The category of the error for the deletion request, if any.                                                                                                       |
| attributes           | from_time [*required*]          | int64    | Start of requested time window, milliseconds since Unix epoch.                                                                                                    |
| attributes           | indexes                              | [string] | List of indexes for the search. If not provided, the search is performed in all indexes.                                                                          |
| attributes           | is_created [*required*]         | boolean  | Whether the deletion request is fully created or not. It can take several minutes to fully create a deletion request depending on the target query and timeframe. |
| attributes           | org_id [*required*]             | int64    | Organization ID.                                                                                                                                                  |
| attributes           | product [*required*]            | string   | Product name.                                                                                                                                                     |
| attributes           | query [*required*]              | string   | Query for creating a data deletion request.                                                                                                                       |
| attributes           | starting_at [*required*]        | string   | Starting time of the process to delete the requested data.                                                                                                        |
| attributes           | status [*required*]             | string   | Status of the deletion request.                                                                                                                                   |
| attributes           | to_time [*required*]            | int64    | End of requested time window, milliseconds since Unix epoch.                                                                                                      |
| attributes           | total_unrestricted [*required*] | int64    | Total number of elements to be deleted. Only the data accessible to the current user that matches the query and timeframe provided will be deleted.               |
| attributes           | updated_at [*required*]         | string   | Update time of the deletion request.                                                                                                                              |
| data                 | id [*required*]                 | string   | The ID of the created data deletion request.                                                                                                                      |
| data                 | type [*required*]               | string   | The type of the request created.                                                                                                                                  |
|                      | meta                                 | object   | The metadata of the data deletion response.                                                                                                                       |
| meta                 | count_product                        | object   | The total deletion requests created by product.                                                                                                                   |
| additionalProperties | <any-key>                            | int64    |
| meta                 | count_status                         | object   | The total deletion requests created by status.                                                                                                                    |
| additionalProperties | <any-key>                            | int64    |
| meta                 | next_page                            | string   | The next page when searching deletion requests created in the current organization.                                                                               |
| meta                 | product                              | string   | The product of the deletion request.                                                                                                                              |
| meta                 | request_status                       | string   | The status of the executed request.                                                                                                                               |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "created_at": "2024-01-01T00:00:00.000000Z",
      "created_by": "test.user@datadoghq.com",
      "customer_message": "Your deletion request is being processed.",
      "displayed_total": 100,
      "error_category": "validation_error",
      "from_time": 1672527600000,
      "indexes": [
        "test-index",
        "test-index-2"
      ],
      "is_created": true,
      "org_id": 321813,
      "product": "logs",
      "query": "service:xyz host:abc",
      "starting_at": "2024-01-01T02:00:00.000000Z",
      "status": "pending",
      "to_time": 1704063600000,
      "total_unrestricted": 100,
      "updated_at": "2024-01-01T00:00:00.000000Z"
    },
    "id": "1",
    "type": "deletion_request"
  },
  "meta": {
    "count_product": {
      "<any-key>": "integer"
    },
    "count_status": {
      "<any-key>": "integer"
    },
    "next_page": "cGFnZTI=",
    "product": "logs",
    "request_status": "canceled"
  }
}
```

{% /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" %}
Forbidden
{% 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="412" %}
Precondition failed error
{% 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 %}

{% tab title="500" %}
Internal server error
{% 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
# 
 \# Path parameters export product="CHANGE_ME" \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/deletion/data/${product}" \
-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": {
      "displayed_total": 100,
      "from": 1672527600000,
      "indexes": [
        "test-index",
        "test-index-2"
      ],
      "query": {
        "host": "abc",
        "service": "xyz"
      },
      "to": 1704063600000
    },
    "type": "create_deletion_req"
  }
}
EOF 
                        
##### 

```go
// Creates a data deletion request 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.CreateDataDeletionRequestBody{
		Data: datadogV2.CreateDataDeletionRequestBodyData{
			Attributes: datadogV2.CreateDataDeletionRequestBodyAttributes{
				DisplayedTotal: 100,
				From:           1672527600000,
				Indexes: []string{
					"test-index",
					"test-index-2",
				},
				Query: map[string]string{
					"host":    "abc",
					"service": "xyz",
				},
				To: 1704063600000,
			},
			Type: datadogV2.CREATEDATADELETIONREQUESTBODYDATATYPE_CREATE_DELETION_REQ,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewDataDeletionApi(apiClient)
	resp, r, err := api.CreateDataDeletionRequest(ctx, "logs", body)

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `DataDeletionApi.CreateDataDeletionRequest`:\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
// Creates a data deletion request returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.DataDeletionApi;
import com.datadog.api.client.v2.model.CreateDataDeletionRequestBody;
import com.datadog.api.client.v2.model.CreateDataDeletionRequestBodyAttributes;
import com.datadog.api.client.v2.model.CreateDataDeletionRequestBodyData;
import com.datadog.api.client.v2.model.CreateDataDeletionRequestBodyDataType;
import com.datadog.api.client.v2.model.CreateDataDeletionResponseBody;
import java.util.Arrays;
import java.util.Map;

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

    CreateDataDeletionRequestBody body =
        new CreateDataDeletionRequestBody()
            .data(
                new CreateDataDeletionRequestBodyData()
                    .attributes(
                        new CreateDataDeletionRequestBodyAttributes()
                            .displayedTotal(100L)
                            .from(1672527600000L)
                            .indexes(Arrays.asList("test-index", "test-index-2"))
                            .query(
                                Map.ofEntries(
                                    Map.entry("host", "abc"), Map.entry("service", "xyz")))
                            .to(1704063600000L))
                    .type(CreateDataDeletionRequestBodyDataType.CREATE_DELETION_REQ));

    try {
      CreateDataDeletionResponseBody result = apiInstance.createDataDeletionRequest("logs", body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling DataDeletionApi#createDataDeletionRequest");
      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"
##### 

```python
"""
Creates a data deletion request returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.data_deletion_api import DataDeletionApi
from datadog_api_client.v2.model.create_data_deletion_request_body import CreateDataDeletionRequestBody
from datadog_api_client.v2.model.create_data_deletion_request_body_attributes import (
    CreateDataDeletionRequestBodyAttributes,
)
from datadog_api_client.v2.model.create_data_deletion_request_body_data import CreateDataDeletionRequestBodyData
from datadog_api_client.v2.model.create_data_deletion_request_body_data_type import (
    CreateDataDeletionRequestBodyDataType,
)

body = CreateDataDeletionRequestBody(
    data=CreateDataDeletionRequestBodyData(
        attributes=CreateDataDeletionRequestBodyAttributes(
            displayed_total=100,
            _from=1672527600000,
            indexes=[
                "test-index",
                "test-index-2",
            ],
            query=dict(
                host="abc",
                service="xyz",
            ),
            to=1704063600000,
        ),
        type=CreateDataDeletionRequestBodyDataType.CREATE_DELETION_REQ,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = DataDeletionApi(api_client)
    response = api_instance.create_data_deletion_request(product="logs", 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
# Creates a data deletion request returns "OK" response

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

body = DatadogAPIClient::V2::CreateDataDeletionRequestBody.new({
  data: DatadogAPIClient::V2::CreateDataDeletionRequestBodyData.new({
    attributes: DatadogAPIClient::V2::CreateDataDeletionRequestBodyAttributes.new({
      displayed_total: 100,
      from: 1672527600000,
      indexes: [
        "test-index",
        "test-index-2",
      ],
      query: {
        host: "abc", service: "xyz",
      },
      to: 1704063600000,
    }),
    type: DatadogAPIClient::V2::CreateDataDeletionRequestBodyDataType::CREATE_DELETION_REQ,
  }),
})
p api_instance.create_data_deletion_request("logs", 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"
##### 

```rust
// Creates a data deletion request returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_data_deletion::DataDeletionAPI;
use datadog_api_client::datadogV2::model::CreateDataDeletionRequestBody;
use datadog_api_client::datadogV2::model::CreateDataDeletionRequestBodyAttributes;
use datadog_api_client::datadogV2::model::CreateDataDeletionRequestBodyData;
use datadog_api_client::datadogV2::model::CreateDataDeletionRequestBodyDataType;
use std::collections::BTreeMap;

#[tokio::main]
async fn main() {
    let body = CreateDataDeletionRequestBody::new(CreateDataDeletionRequestBodyData::new(
        CreateDataDeletionRequestBodyAttributes::new(
            100,
            1672527600000,
            BTreeMap::from([
                ("host".to_string(), "abc".to_string()),
                ("service".to_string(), "xyz".to_string()),
            ]),
            1704063600000,
        )
        .indexes(vec!["test-index".to_string(), "test-index-2".to_string()]),
        CreateDataDeletionRequestBodyDataType::CREATE_DELETION_REQ,
    ));
    let configuration = datadog::Configuration::new();
    let api = DataDeletionAPI::with_config(configuration);
    let resp = api
        .create_data_deletion_request("logs".to_string(), 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
/**
 * Creates a data deletion request returns "OK" response
 */

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

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

const params: v2.DataDeletionApiCreateDataDeletionRequestRequest = {
  body: {
    data: {
      attributes: {
        displayedTotal: 100,
        from: 1672527600000,
        indexes: ["test-index", "test-index-2"],
        query: {
          host: "abc",
          service: "xyz",
        },
        to: 1704063600000,
      },
      type: "create_deletion_req",
    },
  },
  product: "logs",
};

apiInstance
  .createDataDeletionRequest(params)
  .then((data: v2.CreateDataDeletionResponseBody) => {
    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 %}
