## Start a session

`POST /v1/openlines/sessions/start`

Starts a session in an Open Line chat. If a session is already active, joins the operator to it.

Scope: `imopenlines`. A write-enabled key is required.

## Request body fields

| Field | Type | Required | Description |
|---|---|---|---|
| `chatId` | number \| string | Yes | Positive safe integer. Open Line chat object id from [session search](../sessions.md) or [client chat open](../sessions/open.md). Numeric strings are accepted. |

## Examples

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/start" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"chatId":123}'
```

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/start" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"chatId":123}'
```

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/openlines/sessions/start', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"chatId":123}),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error.message);
console.log(result.data);
```

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/openlines/sessions/start', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    Authorization: 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"chatId":123}),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error.message);
console.log(result.data);
```

## Response fields

| Field | Type | Description |
|---|---|---|
| `success` | boolean | `true` |
| `data` | object | Operation result |
| `data.chatId` | number | Open Line chat id |
| `data.started` | boolean | Action accepted |

## Response example

```json
{
  "success": true,
  "data": {
    "chatId": 123,
    "started": true
  }
}
```

## Error response example

403: the calling employee has no access.

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ACCESS_DENIED",
    "message": "Access denied"
  }
}
```

## Errors

| HTTP | Code | Condition |
|---|---|---|
| 400 | `INVALID_CHAT_ID` | Invalid chat id |
| 403 | `SCOPE_DENIED` | Missing imopenlines scope |
| 403 | `BITRIX_ACCESS_DENIED` | No access in Bitrix24 |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | Key forbids writes |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 identifies an absent chat |
| 422 | `BITRIX_ERROR` | Business refusal; message is preserved |
| 502 | `OPENLINE_OPERATOR_FAILED` | Unexpected result or unapplied pause state |

[System errors](../../errors.md).

## Known details

The CHAT_ID alias is accepted. Bitrix24 checks permissions.

## See also

- [Operator actions](../operator.md)
- [Session search](../sessions.md)
