
## Register a command

`POST /v1/bots/:botId/commands`

Registers a new bot slash command. Vibecode accepts a flat format and automatically wraps it into `fields` for Bitrix24.

## Request fields (body)

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `command` | string | yes | — | Command text without `/` (for example, `help`) |
| `title` | string/object | no | — | Title. A string or a multilingual object `{ "en": "Help", "de": "Hilfe" }` |
| `params` | string/object | no | — | Parameters description. A string or an object `{ "en": "topic", "de": "Thema" }` |
| `common` | string | no | `"N"` | `"Y"` — available in all chats, `"N"` — only in the private dialog with the bot and chats with the bot |
| `hidden` | string | no | `"N"` | `"Y"` — hide from the command list |
| `extranetSupport` | string | no | `"N"` | `"Y"` — available to extranet users |

## Examples

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/commands \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "help",
    "title": { "en": "Help", "de": "Hilfe" },
    "params": { "en": "topic", "de": "Thema" },
    "common": "Y"
  }'
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/commands \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "help",
    "title": { "en": "Help", "de": "Hilfe" },
    "params": { "en": "topic", "de": "Thema" },
    "common": "Y"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/commands', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    command: 'help',
    title: { en: 'Help', de: 'Hilfe' },
    params: { en: 'topic', de: 'Thema' },
    common: 'Y',
  }),
})

const { success, data } = await res.json()
console.log('Command ID:', data.commandId)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/commands', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    command: 'help',
    title: { en: 'Help', de: 'Hilfe' },
    params: { en: 'topic', de: 'Thema' },
    common: 'Y',
  }),
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `command.id` | number | ID of the registered command |
| `command.botId` | number | Bot ID |
| `command.command` | string | Command text (with `/`) |
| `command.common` | boolean | Available in all chats |
| `command.hidden` | boolean | Hidden from the list |
| `command.extranetSupport` | boolean | Available to extranet users |

## Response example

```json
{
  "success": true,
  "data": {
    "command": {
      "id": 117,
      "botId": 1327,
      "command": "/help",
      "common": true,
      "hidden": false,
      "extranetSupport": false
    }
  }
}
```

## Error response example

502 — Bitrix24 error:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Command 'help' already registered"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_BOT_ID` | `botId` is not a number |
| 404 | `BOT_NOT_FOUND` | No bot found with this ID |
| 403 | `BOT_ACCESS_DENIED` | The bot belongs to a different API key |
| 502 | `BITRIX_ERROR` | Bitrix24 error (error text in `message`) |
| 403 | `SCOPE_DENIED` | API key lacks the `imbot` scope |
| 401 | `TOKEN_MISSING` | API key has no configured tokens |

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

## Known specifics

**Idempotency:** a repeat call with the same `command` for the same bot returns the existing command unchanged. To update it, use `PATCH`.

**Multilingual:** `title` and `params` accept either a string or an object with language keys (`ru`, `en`, `de`, etc.).

**Event:** when a user invokes the command, the `ONIMBOTV2COMMANDADD` event fires.

## See also

- [List commands](/docs/bots/commands/list)
- [Answer a command](/docs/bots/commands/answer)
- [Events](/docs/bots/events)
- [Bot platform](/docs/bots)
- [Limits and optimization](/docs/optimization)
