## Delete a section

`DELETE /v1/calendar-sections/:id`

Deletes a calendar section by identifier. A deleted section cannot be restored through the API — repeat [`POST /v1/calendar-sections`](./create.md) if you need it again.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Section identifier |
| `type` (query or body) | string | yes | Calendar type: `user`, `group`. A section cannot be located by `id` alone — the `type` + `ownerId` pair is required |
| `ownerId` (query or body) | number | yes | Calendar owner identifier |

The `type` and `ownerId` parameters are accepted both in the query string and in the body — if both are passed, **the query string takes priority**. If a parameter is omitted in both places, the Vibecode API returns `400 MISSING_REQUIRED_PARAMS` before calling Bitrix24.

## Examples

### curl — personal key

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/calendar-sections/42?type=user&ownerId=1" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/calendar-sections/42?type=user&ownerId=1" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const params = new URLSearchParams({ type: 'user', ownerId: '1' })
const res = await fetch(`https://vibecode.bitrix24.com/v1/calendar-sections/42?${params}`, {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

if (res.status === 204) {
  console.log('Section deleted')
}
```

### JavaScript — OAuth application

```javascript
const params = new URLSearchParams({ type: 'user', ownerId: '1' })
const res = await fetch(`https://vibecode.bitrix24.com/v1/calendar-sections/42?${params}`, {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

if (res.status === 204) {
  console.log('Deleted')
}
```

## Response

On successful deletion, an HTTP status `204 No Content` with an empty body is returned. Success is indicated by the response code, not by the content.

## Response example

```
HTTP/1.1 204 No Content
```

## Error response example

400 — `type` and `ownerId` are missing:

```json
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_PARAMS",
    "message": "DELETE /v1/calendar-sections/:id requires type, ownerId (query or body). Example: DELETE /v1/calendar-sections/:id?type=...&ownerId=...",
    "missing": ["type", "ownerId"]
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `MISSING_REQUIRED_PARAMS` | `type` or `ownerId` was not passed — neither in the query string nor in the body. The `missing` field in the response lists the specific omitted keys |
| 422 | `BITRIX_ERROR` | A section with the specified `id` does not exist, is already deleted, or is inaccessible |
| 403 | `SCOPE_DENIED` | The API key does not have the `calendar` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The API key is in read-only mode — writing is forbidden |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is temporarily unavailable — retry the request later |

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

## Known specifics

**There is no confirmation.** The request runs without interactive confirmation and without an undo — the operation is irreversible. Before deleting, make sure you no longer need the section. If it still contains events you need, move them to another section in advance via [`PATCH /v1/calendar-events/:id`](/docs/entities/calendar-events/update) with a new `sectionId`.

**Query string takes priority over the body.** If `type` and `ownerId` are passed both in `?type=...&ownerId=...` and in the JSON body, the values from the query string are taken. The body is used only as a fallback source when the parameters are absent from the query string.

## See also

- [Section list](./list.md)
- [Batch of operations](./batch.md)
- [Calendar events](/docs/entities/calendar-events)
