## Unpublish site

`POST /v1/sites/:id/unpublish`

Unpublishes a site in the Bitrix24 account.

## 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 the response is `404 ENTITY_NOT_FOUND` |

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/unpublish" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/233/unpublish" \
  -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/unpublish', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success, data } = await res.json()
console.log('Published:', data.active)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/233/unpublish', {
  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 |
| `data.deleted` | boolean | Whether the site is in the trash. In [`GET /v1/sites`](/docs/entities/sites/list) responses the same field comes as the 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": false,
    "type": "PAGE"
  }
}
```

## Error response example

404 — the site is 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 unpublishing or rejected it. The reason is in `message` |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is unavailable on the Bitrix24 account. Ask the account administrator to enable it — while the module is off, 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 permissions, 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

- **Site pages keep their published flag.** After the call, the site's pages still have `active: true`. To unpublish a single page, use `POST /v1/pages/:id/unpublish`.
- **Unpublishing again succeeds without an error.** For an already unpublished site the response is `200`, and the site does not change.

## See also

- [Publish site](/docs/entities/sites/publication)
- [Site public URL](/docs/entities/sites/public-url)
- [Get site](/docs/entities/sites/get)
- [Move site to trash](/docs/entities/sites/trash)
- [Unpublish folder](/docs/entities/sites/folders/unpublish)
- [Pages](/docs/entities/pages)
