## Number of a chat's links

`GET /v1/chats/:chatId/links/counter`

Returns how many links were sent in the chat's messages, without loading the links themselves.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `chatId` (path) | number | yes | Chat ID. Get it from [`GET /v1/chats/recent`](/docs/chats/discovery/recent) |

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 "https://vibecode.bitrix24.com/v1/chats/1001/links/counter" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

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

const { data } = await res.json()
console.log('Links:', data.counter)
```

### JavaScript — OAuth application

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

const { data } = await res.json()
console.log('Links:', data.counter)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.counter` | number | Number of links in the chat |

## Response example

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

## Error response example

400 — a query parameter was passed:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Query parameter `limit` is not accepted by GET /v1/chats/:chatId/links/counter. It takes no query parameters."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_CHAT_ID` | `chatId` is not a positive integer. Checked before any call to Bitrix24 |
| 400 | `INVALID_PARAMS` | A body field or query parameter was passed. Checked before any call to Bitrix24 |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned a generic "not found" error; the portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | `error.b24Code` is `ACCESS_ERROR` — the employee has no access to the chat, or there is no such chat |

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

## Known specifics

**Only the visible history is counted.** If the employee can see the chat history only from a certain point on, links before that point are not counted.

## See also

- [List a chat's links](/docs/chats/messages/links)
- [Remove a link from the list](/docs/chats/messages/links-delete)
- [Messages](/docs/chats/messages)
