## Unpin a message

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

Unpins a message: it is removed from its chat's list of pinned messages. The chat is resolved from the message, so no `dialogId` is needed.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `messageId` (path) | number | yes | ID of the pinned message, a positive integer — the `messageId` field from the [list of pinned messages](/docs/chats/messages/pins) |

No body and no query parameters are accepted: any body field or query parameter is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

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

### curl — OAuth application

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/chats/messages/1001/pin" \
  -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/1001/pin', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success } = await res.json()
console.log('Unpinned:', success)
```

### JavaScript — OAuth application

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

const { success } = await res.json()
console.log('Unpinned:', success)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | An empty array |

## Response example

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

## Error response example

422 — there is no such message:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "MESSAGE_NOT_FOUND",
    "b24Code": "MESSAGE_NOT_FOUND"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `messageId` is not a positive integer, or a body field or query parameter was passed. Checked before any call to Bitrix24 |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 reported "not found"; the portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error; the code is in `error.b24Code`, for example `MESSAGE_NOT_FOUND` — there is no such message |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | A read-only key cannot unpin messages — see [access rights](/docs/access-rights) |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**Unpinning again succeeds.** Unpinning a message that is not pinned returns the same response as unpinning a pinned one. You do not need to check whether the message is pinned before the call.

## See also

- [List pinned messages](/docs/chats/messages/pins)
- [Pin a message](/docs/chats/messages/pins-create)
- [Number of pinned messages](/docs/chats/messages/pins-count)
- [Messages](/docs/chats/messages)
