> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Message

> Remove a message for a current user.

### Recipes

<AccordionGroup>
  <Accordion title="Delete messages from all chat histories">
    <Steps>
      <Step title="1. Specify if you want to delete messages from all chat histories">
        Set a `force` parameter to `1` to delete messages from all chat histories.

        ```curl {4} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
        -d "force=1" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="2. Set the IDs of the messages">
        Specify the IDs of the messages via comma to refer to specific messages that should be deleted from all users' histories.

        ```curl {5} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
        -d "force=1" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="3. As a result, the messages will be deleted from all chat histories.">
        If you're not the owner of the dialog, the API will return the following message: "WrongPermissions". This means that a user doesn't have permissions to delete a message from all users' histories.

        ```curl theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
        -d "force=1" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Delete messages from your own chat history">
    <Steps>
      <Step title="1. Set the IDs of the messages">
        Specify the IDs of the messages via comma to refer to specific messages that should be deleted from your own chat history.

        ```curl {4} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="2. As a result, the messages are removed for a user who has sent the request without affecting chat histories of other users.">
        ```curl theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Delete messages from specific user chat history with API key">
    <Steps>
      <Step title="1. Use 'Authorization' header to pass API key">
        ```curl {3} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="2. Use 'On-Behalf-Of' header to pass user id">
        To execute a request on behalf of a specific user.

        ```curl {4} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="3. Set the IDs of the messages">
        Specify the IDs of the messages via comma to refer to specific messages that should be deleted from the chat history of the user with ID **123**.

        ```curl {5} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="4. As a result, the messages are removed for a user who has sent the request without affecting chat histories of other users.">
        ```curl theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -H "On-Behalf-Of: 123" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Delete messages from all chat histories">
    <Steps>
      <Step title="1. Use 'Authorization' header to pass API key">
        ```curl {3} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="2. Set the IDs of the messages">
        Specify the IDs of the messages via comma to refer to specific messages that should be deleted from all users' histories.

        ```curl {4} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>

      <Step title="3. As a result, the messages will be deleted from all chat histories.">
        If the API key is not related to the same application as the messages, the API will return the following message: "WrongPermissions". This means that a user doesn't have permission to delete a message.

        ```curl theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Hard delete messages from chat history with API key">
    <Steps>
      <Step title="1. Specify if you want to delete messages from all chat histories">
        Set a `force` parameter to `1` to delete messages from all chat histories.

        ```curl {5} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        -d "force=1" \
        ```
      </Step>

      <Step title="2. Use 'Authorization' header to pass API key">
        ```curl {3} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        -d "force=1" \
        ```
      </Step>

      <Step title="3. Set the IDs of the messages">
        Specify the IDs of the messages via comma to refer to specific messages that should be deleted from all users' histories.

        ```curl {4} theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        -d "force=1" \
        ```
      </Step>

      <Step title="4. As a result, the messages will be deleted from all chat histories.">
        If the API key is not related to the same application as the messages, the API will return the following message: "WrongPermissions". This means that a user doesn't have permission to delete a message.

        ```curl theme={null}
        curl -X DELETE \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
        -d "force=1" \
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

Any user in the dialog’s `occupants_ids` is able to remove a message from the dialog. The message will **only** be removed for the **current user.** The message will still be viewable in the chat history for all other users in the dialog.

You may be wondering why this request only deletes the message for the current user. It is to allow deletion functionality within your app and ensure the message does not reappear in the user chat history, but without affecting the history of other users.

It is possible to completely remove a message by the **owner** - pass `force=1`.

Starting from version 2.52.0, **admins** can also completely remove messages of other users using `force=1`.

### Path Parameters

<ParamField path="chat_message_id" type="string" requires> ID of the message. Generated automatically by the server after message creation. </ParamField>

### Body Parameters

<ParamField body="force" type="integer"> Delete message for everyone. Set `force=1` to perform. Only the owner can do it. Starting from v2.52.0, for dialog `type=1` (PUBLIC\_GROUP) and `type=2` (GROUP), admins can also delete messages of other occupants.</ParamField>

### Headers

<ParamField header="QB-Token" type="string" required> A user or application session token. See [Authentication](/reference/authentication) page to learn more about session tokens. Must be used either QB-Token or Authorization. </ParamField>
<ParamField header="Authorization" type="string" default="ApiKey {your_api_key}"> API key from Dashboard. Expected format: `ApiKey {your_api_key}`. Must be used either QB-Token or Authorization.</ParamField>
<ParamField header="On-Behalf-Of" type="string">User ID. The user ID of the user on whose behalf the request is being made.</ParamField>

### Responses

<AccordionGroup>
  <Accordion title="200">
    A successful response

    <ResponseField name="SuccessfullyDeleted" type="object">
      <Expandable title="properties">
        <ResponseField name="ids" type="array of strings" />
      </Expandable>
    </ResponseField>

    <ResponseField name="NotFound" type="object">
      <Expandable title="properties">
        <ResponseField name="ids" type="array of strings" />
      </Expandable>
    </ResponseField>
  </Accordion>

  <Accordion title="404">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE \
  -H "Content-Type: application/json" \
  -H "QB-Token: eddf864695d72d33b959eec2ae6c640d817dfada" \
  https://api.quickblox.com/chat/Message/5d76b949a0eb4721f80b72ab,5d76b657a28f9a0cc7cb0f99,5d76b6sdfff9a0cc7cb023.json
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "SuccessfullyDeleted": {
      "ids": [
        "5d76b657a28f9a0cc7cb0f99",
        "5d76b949a0eb4721f80b72ab"
      ]
    },
    "NotFound": {
      "ids": [
        "5d76b6sdfff9a0cc7cb023"
      ]
    }
  }
  ```

  ```json 404 theme={null}
  // All messages don't exist
  {
    "errors": ["The resource wasn't found"]
  }
  ```
</ResponseExample>
