## Open a client chat

`POST /v1/openlines/sessions/open`

Finds a client chat by connector user code and returns its identifier.

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

## Request body fields

| Field | Type | Required | Description |
|---|---|---|---|
| `userCode` | string | Yes | Connector code: `<connector>\|<lineId>\|<externalChatId>\|<userId>`, obtained from the connector integration. The code is passed unchanged. |

## Examples

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/open" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"userCode":"livechat|3|VIBE-PROBE|42"}'
```

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/openlines/sessions/open" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"userCode":"livechat|3|VIBE-PROBE|42"}'
```

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/openlines/sessions/open', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"userCode":"livechat|3|VIBE-PROBE|42"}),
});
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/open', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    Authorization: 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"userCode":"livechat|3|VIBE-PROBE|42"}),
});
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 |

## Response example

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

## 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 | `MISSING_REQUIRED_FIELDS` | Missing or empty userCode |
| 403 | `SCOPE_DENIED` | Missing imopenlines scope |
| 403 | `BITRIX_ACCESS_DENIED` | No access in Bitrix24 |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | Key forbids writes |
| 422 | `BITRIX_ERROR` | Business refusal; message is preserved |
| 502 | `OPENLINE_OPERATOR_FAILED` | Unexpected result or unapplied pause state |

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

## Known details

No access and an absent client both return 403: Bitrix24 does not distinguish them.

## See also

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