## Delete a chat's message content

**delete** `/v1/chats/{chat}/messages`

Deletes the content of every message in one chat up to a cutoff from what Linq stores, and normally received files' copies at the provider; it does not unsend anything, the customer's device keeps its copies, and the provider keeps its own copy of message text.

`before` is the id of a message in this chat: the request covers it and
every earlier message in the chat's sequence, and never a message after
it, including one that arrives later. An id that is not a message in this
chat answers `404 not_found`.

The `202` returns the request; read its progress with
`GET /v1/content_deletions/{content_deletion}`, or wait for the chat's
`content_deletion.completed` event, which the chat's events read shows as
an entry carrying the completed request. Messages are removed as they
become deletable: one whose send is still being handed to the channel, or
an incoming one whose first event to you is still being delivered, waits
and resumes on its own, and the request stays `blocked` until then. A
received message waits until every delivery of its first event has
succeeded or failed for good, so a failing endpoint delays the request
and a hold on delivery delays it until the hold is released. Each
removed message vanishes from every read, and what is kept is as for the
one-message delete. `completed` means every message in range has no
content left in our database; stored files, and the channel's copies of
files sent or received, can be removed after it, as for the one-message
delete. Linq cannot delete the channel's own copy of message text. The chat itself, and every message
after `before`, stay.

A repeat with the same Idempotency-Key returns the same request in its
current state; a message already deleted is counted `already_gone`.
Idempotency-Key is required; reusing it for a different chat or cutoff
answers `409 idempotency_conflict`.

### Path Parameters

- `chat: string`

### Query Parameters

- `before: string`

  The id of the last message to delete, inclusive: a message in this chat.

### Header Parameters

- `"Idempotency-Key": string`

### Returns

- `ContentDeletion object { id, before, blocked_reasons, 5 more }`

  A chat-wide deletion request and its progress.

  - `id: string`

    This request's id.

  - `before: string`

    The inclusive cutoff: the id of a message in this chat. The request covers that message and every message before it in the chat's sequence; messages after it, including any that arrive later, are never in range.

  - `blocked_reasons: array of string`

    Why messages are waiting, while `blocked` is above zero: `message_in_flight`, `awaiting_first_delivery` or `content_deletion_busy`. Values may grow.

  - `chat_id: string`

    The chat whose messages the request covers.

  - `completed_at: string`

    When the request completed; null until it has.

  - `counts: object { already_gone, blocked, deleted }`

    Per-message outcomes of one deletion request so far.

    - `already_gone: number`

      Messages whose content was already gone, for example removed by content retention.

    - `blocked: number`

      Messages waiting before their content can be removed. Each resumes on its own.

    - `deleted: number`

      Messages whose stored content this request removed.

  - `created_at: string`

  - `state: string`

    `pending`, `running`, `blocked` or `completed`. A request is never `completed` while a message in its range still has content in our database; stored files, and the channel's copies of files sent or received, can be removed after it completes. `blocked` resumes on its own. Values may grow.

### Example

```http
curl https://whatsapp.messages.api.linqapp.com/v1/chats/$CHAT/messages \
    -X DELETE \
    -H "Authorization: Bearer $LINQ_WHATSAPP_API_KEY"
```

#### Response

```json
{
  "id": "id",
  "before": "before",
  "blocked_reasons": [
    "string"
  ],
  "chat_id": "chat_id",
  "completed_at": "2019-12-27T18:11:19.117Z",
  "counts": {
    "already_gone": 0,
    "blocked": 0,
    "deleted": 0
  },
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": "state"
}
```
