## Move a site to trash

`POST /v1/sites/:id/trash`

Moves a site to the trash and unpublishes it. This is not a physical deletion: the site can be restored from the trash.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Site ID, a positive integer. List: [`GET /v1/sites`](/docs/entities/sites/list) |
| `scope` (query) | string | no | Internal landing scope: `KNOWLEDGE` / `GROUP` / `MAINPAGE`. Pass it if the site belongs to that scope. Otherwise `404 ENTITY_NOT_FOUND` is returned |

The request body is empty or `{}`. Any field in the body is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/233/trash" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/233/trash" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/233/trash', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success, data } = await res.json()
console.log('In trash:', data.deleted)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/233/trash', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data.id` | number | Site ID |
| `data.active` | boolean | Whether the site is published. After moving to trash — `false` |
| `data.deleted` | boolean | Whether the site is in the trash. After moving — `true`. In [`GET /v1/sites`](/docs/entities/sites/list) responses the same field comes as a string `"Y"` / `"N"` |
| `data.type` | string | Site type: `PAGE`, `STORE`, `KNOWLEDGE` and other values from [`GET /v1/sites/fields`](/docs/entities/sites/fields) |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 233,
    "active": false,
    "deleted": true,
    "type": "PAGE"
  }
}
```

## Error response example

404 — site not found:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Site not found or not visible"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `id` is not a positive integer |
| 400 | `INVALID_SCOPE` | `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 400 | `INVALID_PARAMS` | A request body was passed. The method accepts an empty body or `{}` |
| 404 | `ENTITY_NOT_FOUND` | No site with this `id` exists, it is not accessible to the key's user, or it belongs to a different `scope` |
| 404 | `ENTITY_NOT_FOUND` | The site was not found after the operation: it was deleted by a concurrent request |
| 422 | `BITRIX_ERROR` | Bitrix24 did not confirm the site operation or rejected it. The reason is in `message` |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is unavailable on the Bitrix24 account. Ask the Bitrix24 account administrator to enable it. While the module is disabled, a retry returns the same refusal |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied access: the key's user has no permissions on this site or no administrator rights, or the feature is unavailable on the Bitrix24 account |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The API key is read-only |
| 403 | `SCOPE_DENIED` | The API key does not have the `landing` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |

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

## Known specifics

- **A site in the trash is not returned by ID.** [`GET /v1/sites/:id`](/docs/entities/sites/get) returns `404 ENTITY_NOT_FOUND` for it. Find such a site with [`GET /v1/sites`](/docs/entities/sites/list) and `filter[deleted]=Y`.
- **Moving a site that is already in the trash succeeds without an error.** The response is `200`, and the site does not change.

## See also

- [Restore a site](/docs/entities/sites/restore)
- [Delete a site](/docs/entities/sites/delete)
- [Unpublish a site](/docs/entities/sites/unpublish)
- [List sites](/docs/entities/sites/list)
