## Count favorite messages

`GET /v1/chats/:dialogId/favorites/count`

Returns how many messages the current user has added to favorites in one chat, without loading the messages themselves.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dialogId` (path) | string | yes | `chat` followed by the actual chat ID returned when you [load the chat](/docs/chats/messages/load), including a one-to-one chat. The endpoint rejects a numeric user ID and `me`. |

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

## Examples

### curl — personal key

```bash
curl -X GET "https://vibecode.bitrix24.com/v1/chats/chat1945/favorites/count" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X GET "https://vibecode.bitrix24.com/v1/chats/chat1945/favorites/count" \
  -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/chat1945/favorites/count', {
  method: 'GET',
  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/chat1945/favorites/count', {
  method: 'GET',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const { data } = await res.json()
console.log(data)
```

## Response fields

| Field | Type | Description |
|-------|------|-------------|
| `success` | boolean | `true` |
| `data.counter` | number | Favorite message counter |

## Response example

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

## Error response example

400 — unexpected parameter:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Query parameter `ownerId` is not accepted by GET /v1/chats/:dialogId/favorites/count. 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 `ACCESS_ERROR` — the employee has no access to the chat, or there is no such chat |
| 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 |
| 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).

## See also

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