## Per-session metrics

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

`POST /v1/openlines/sessions/stats`

Batch metrics for specific sessions — time to answer and close, message counters, number of transfers, rating. Up to 100 identifiers per call.

## Request fields (body)

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

Duplicates in `sessionId` are collapsed: each unique identifier is returned once. A nonexistent, foreign, or inaccessible `sessionId` does not cause an error — an object is returned for it with the `sessionId` itself and `null` in all metrics.

## 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 each unique requested `sessionId`, including inaccessible ones (with `null` fields).

| Key | Description |
|---|---|
| `sessionId` | Session identifier |
| `waitAnswer` / `waitClose` | Time to first answer and to close, seconds |
| `messagesCount` | Number of messages in the session |
| `messagesOperatorCount` / `messagesClientCount` | Operator and customer messages |
| `transfersCount` | Number of reassignments |
| `kpiFirstAnswer` | Whether the first-answer SLA was met |
| `vote` | Customer rating |
| `voteHead` | Supervisor rating (`null` if no right) |

## Response example

The third session is inaccessible or does not exist — 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 batch:

```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 tariff does not include Open Channels statistics (`report_open_lines`) |
| 400 | `MISSING_PARAMS` | `sessionId` is an empty array or missing |
| 400 | `INVALID_PARAMS` | A non-numeric element in `sessionId` |
| 400 | `BATCH_LIMIT_EXCEEDED` | More than 100 unique identifiers (after collapsing duplicates) |
| 422 | `METHOD_NOT_YET_AVAILABLE` | The `imopenlines 26.700.0` update has not reached the portal yet |

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

## See also

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