## Chat with a user

`GET /v1/calls/log/chat`

Returns the ID of the key owner's private chat with an employee. If the chat does not exist yet, the call creates it.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|-------|----------|
| `userId` (query) | integer | yes | Employee ID. List: [`GET /v1/users`](/docs/entities/users/list). In the call journal, take the `callData.userId` field from the [call journal list](/docs/calls/log/list) |

## Examples

### curl — personal key

```bash
curl -X GET "https://vibecode.bitrix24.com/v1/calls/log/chat?userId=77" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X GET "https://vibecode.bitrix24.com/v1/calls/log/chat?userId=77" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/calls/log/chat?userId=77', {
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
})
const { success, data, error } = await response.json()
console.log(success ? data.chatId : error.code)
```

### JavaScript — OAuth application

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/calls/log/chat?userId=77', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const { success, data, error } = await response.json()
console.log(success ? data.chatId : error.code)
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data.chatId` | integer | ID of the private chat with the employee |

## Response example

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

## Error response example

400 — `userId` is missing or not a positive integer:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "userId must be a positive integer"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `userId` is missing or not a positive integer |
| 422 | `BITRIX_ERROR` | Bitrix24 did not return a chat: `Bitrix24 did not return a chat` |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 403 | `SCOPE_DENIED` | The key lacks the `call` scope |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied access |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens configured |
| 429 | `RATE_LIMITED` | The Bitrix24 request limit is exceeded |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time |

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

## Known specifics

**`GET` requires a key with write access.** The call can create a chat, so a read-only key gets `403 WRITE_BLOCKED_READONLY_KEY` before Bitrix24 is called, even though the method is `GET`.

## See also

- [Call journal](/docs/calls/log)
- [List call journal](/docs/calls/log/list)
- [Delete journal entry](/docs/calls/log/delete)
