## Remove a message from favorites

`DELETE /v1/chats/messages/:messageId/favorite`

Removes a message from the current user’s favorites in the chat where the message was sent.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `messageId` (path) | integer | yes | Message id from [message history](/docs/chats/messages/list) |

Requires the `im` scope. The credentials identify the current user. The API rejects parameters that specify the owner and any unknown parameters.

The body may be absent or `{}`. No body fields or query parameters are accepted. Use an API key with write access.

## Examples

### curl — personal key

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/chats/messages/845/favorite" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/chats/messages/845/favorite" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/messages/845/favorite', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})
const { data } = await res.json()
console.log(data)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/messages/845/favorite', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const { data } = await res.json()
console.log(data)
```

## Response

| Field | Type | Description |
|-------|------|-------------|
| `success` | boolean | `true` |
| `data` | boolean | `true` — the command succeeded |

## Response example

```json
{
  "success": true,
  "data": true
}
```

## Error response example

400 — unexpected parameter:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Query parameter `ownerId` is not accepted by DELETE /v1/chats/messages/:messageId/favorite. It takes no query parameters."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|------|-------------|
| 400 | `INVALID_PARAMS` | Malformed ID, or an unexpected or repeated parameter or body field |
| 422 | `BITRIX_ERROR` | `error.b24Code` is `MESSAGE_NOT_FOUND` — there is no message with this id |
| 401 | `MISSING_API_KEY` | No API key was provided |
| 401 | `TOKEN_MISSING` | No Bitrix24 credentials are configured |
| 403 | `SCOPE_DENIED` | The key does not have im scope |
| 403 | `BITRIX_ACCESS_DENIED` | The current user has no access |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key cannot change Bitrix24 data |
| 404 | `ENTITY_NOT_FOUND` | The record was not found |
| 422 | `BITRIX_ERROR` | Bitrix24 refused the operation with another code, which is in `error.b24Code` |

[Common API errors](/docs/errors).

## Known specifics

If the message is not in favorites, the response is the same: `data: true`.

## See also

- [Chat configuration](/docs/chats/discovery/configuration)
- [Messages](/docs/chats/messages)
