## Per-session metrics

> **The method ships in the `imopenlines 26.700.0` update and is not yet available on all Bitrix24 accounts.** If the update has not reached your Bitrix24 account yet, the API returns `422 METHOD_NOT_YET_AVAILABLE` — this means the method has not been released on the account yet, not that the integration is broken.

`POST /v1/openlines/sessions/stats`

Batch metrics for specific sessions — time to answer and to close, message counters, number of transfers, rating.

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `sessionId` | number[] | yes | Array of session identifiers, up to 100 elements. Source: [`POST /v1/openlines/sessions/search`](/docs/openlines/sessions/search). A single number is also accepted and wrapped in an array |

Duplicates in `sessionId` are counted once: each unique identifier is returned once. A `sessionId` that does not exist, belongs to someone else, or is not accessible does not cause an error — the response contains an object with that `sessionId` and `null` in every metric.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/stats" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "sessionId": [1024, 1025, 999999] }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/stats" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "sessionId": [1024, 1025, 999999] }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/openlines/sessions/stats', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ sessionId: [1024, 1025, 999999] }),
})
const { data } = await res.json()
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/openlines/sessions/stats', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ sessionId: [1024, 1025, 999999] }),
})
const { data } = await res.json()
```

## Response fields

The response is `{ "success": true, "data": { "sessions": [...] } }`. One object per unique requested `sessionId`, including inaccessible ones (with `null` fields).

| Key | Description |
|---|---|
| `sessionId` | Session identifier |
| `waitAnswer` / `waitClose` | Time to the first answer and to closing, seconds |
| `messagesCount` | Number of messages in the session |
| `messagesOperatorCount` / `messagesClientCount` | Operator and client messages |
| `transfersCount` | Number of reassignments |
| `kpiFirstAnswer` | Whether the first-answer time target (SLA) was met |
| `vote` | Client rating |
| `voteHead` | Supervisor rating (`null` if there is no permission) |

## Response example

The third session is inaccessible or does not exist — it is returned as an object with `null` fields:

```json
{
  "success": true,
  "data": {
    "sessions": [
      { "sessionId": 1024, "waitAnswer": 65, "waitClose": 1330, "messagesCount": 14, "messagesOperatorCount": 6, "messagesClientCount": 8, "transfersCount": 1, "kpiFirstAnswer": true, "vote": "like", "voteHead": 5 },
      { "sessionId": 1025, "waitAnswer": 12, "waitClose": 340, "messagesCount": 5, "messagesOperatorCount": 2, "messagesClientCount": 3, "transfersCount": 0, "kpiFirstAnswer": true, "vote": "none", "voteHead": null },
      { "sessionId": 999999, "waitAnswer": null, "waitClose": null, "messagesCount": null, "messagesOperatorCount": null, "messagesClientCount": null, "transfersCount": null, "kpiFirstAnswer": null, "vote": null, "voteHead": null }
    ]
  }
}
```

## Error response example

`400` — more than 100 identifiers in the request:

```json
{
  "success": false,
  "error": { "code": "BATCH_LIMIT_EXCEEDED", "message": "sessionId batch must not exceed 100 unique ids" }
}
```

## Errors

| HTTP | Code | When |
|---|---|---|
| 403 | `B24_TARIFF_RESTRICTION` | The plan does not include Open Channels statistics (`report_open_lines`) |
| 400 | `INVALID_JSON_BODY` | The request body did not parse as JSON. JSON is parsed before the fields are checked, so the response says nothing about missing parameters |
| 400 | `MISSING_PARAMS` | `sessionId` is an empty array or is missing |
| 400 | `INVALID_PARAMS` | A non-numeric element in `sessionId` |
| 400 | `BATCH_LIMIT_EXCEEDED` | More than 100 unique identifiers (duplicates are counted once) |
| 422 | `METHOD_NOT_YET_AVAILABLE` | The `imopenlines 26.700.0` update has not reached the Bitrix24 account yet. The response contains an `error.release` field set to `imopenlines 26.700.0` |

Full list of system codes — [API errors](/docs/errors).

## See also

- [Session search](/docs/openlines/sessions/search)
- [Reassignment history](/docs/openlines/sessions/transfers)
- [Open Channels statistics](/docs/openlines)
