# Bulk delete conversations using the API

You have the option to delete a filtered subset of conversations or all the conversations in a single request in Customer Experience Insights. Deleted conversations cannot be recovered, so make sure you are deleting the expected number of conversations and with the correct filter.

We strongly recommend first running the command with <var translate="no">MAX_DELETE_COUNT</var>
set to 0. Then, confirm the number of conversations that will be deleted,
and run the API call with the correct <var translate="no">MAX_DELETE_COUNT</var>.

## Prerequisites

1. Make sure that your conversation data is uploaded into Customer Experience Insights.

## Sample Commands

### Delete all conversations

### REST

Refer to the
[`conversations:bulkDelete`](https://docs.cloud.google.com/contact-center/insights/docs/reference/rest/v1/projects.locations.conversations/bulkDelete)
API endpoint for complete details.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: your Google Cloud Platform project ID.
- <var translate="no">FORCE</var>: If true, conversations and linked analyses will be deleted, otherwise only conversations that have not been analyzed will be deleted.
- <var translate="no">MAX_DELETE_COUNT</var>: Maximum number of conversations to delete. If this is lower than number of conversations in the project, API call will return an error.

> [!NOTE]
> **Note:** All the examples are using the global Customer Experience Insights instance. Refer to [Regionalization](https://docs.cloud.google.com/contact-center/insights/docs/regionalization) for instructions on using regional instances.


HTTP method and URL:

```
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkDelete
```


Request JSON body:

```
{
  "force": FORCE,
  "maxDeleteCount": MAX_DELETE_COUNT,
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkDelete"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkDelete" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
}
```

<br />

### (Optional) Delete conversations using a filter

You can view a full list of filters on the [Conversation filtering](https://docs.cloud.google.com/contact-center/insights/docs/filtering) page.

### REST


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: your Google Cloud Platform project ID.
- <var translate="no">FORCE</var>: If true, conversations and linked analyses will be deleted, otherwise only conversations that have not been analyzed will be deleted.
- <var translate="no">MAX_DELETE_COUNT</var>: Maximum number of conversations to delete. If this is lower than the number of conversations in the project, API call will return an error.
- <var translate="no">FILTER</var>: See [List conversations](https://docs.cloud.google.com/contact-center/insights/docs/list-conversations-api) for available filter options.

> [!NOTE]
> **Note:** All the examples are using the global Customer Experience Insights instance. Refer to [Regionalization](https://docs.cloud.google.com/contact-center/insights/docs/regionalization) for instructions on using regional instances.


HTTP method and URL:

```
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkAnalyze
```


Request JSON body:

```
{
  "force": FORCE,
  "maxDeleteCount": MAX_DELETE_COUNT,
  "filter": 'FILTER'
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkAnalyze"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/conversations:bulkAnalyze" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
}
```

<br />

### Poll the operation

Deleting conversations returns a long-running operation. Long-running methods are
asynchronous, and the operation might not yet be completed when the method returns a
response. You can poll the operation to check on its status. See the
[long-running operations page](https://docs.cloud.google.com/contact-center/insights/docs/long-running-operations)
for details and code samples.

### Cancel the operation

### REST


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: your Google Cloud Platform project ID.
- <var translate="no">OPERATION_ID</var>: the ID of the conversation you want to analyze. This value was returned when you created the operation.

> [!NOTE]
> **Note:** All the examples are using the global Customer Experience Insights instance. Refer to [Regionalization](https://docs.cloud.google.com/contact-center/insights/docs/regionalization) for instructions on using regional instances.


HTTP method and URL:

```
POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID:cancel
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d "" \
     "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID:cancel"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -Uri "https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID:cancel" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{}
```

<br />