
## Search sites

`POST /v1/sites/search`

Searches for sites with filtering and auto-pagination. Equivalent to `GET /v1/sites` with filters, but via POST — more convenient for complex requests with many conditions.

## Request fields (body)

| Parameter | Type | Default | Description |
|----------|-----|-----------|---------|
| `filter` | object | — | Filtering by the site's key fields.<br>[Filtering syntax](/docs/filtering) |
| `limit` | number | `50` | Number of records (up to 5000) |
| `offset` | number | `0` | Skip N records. Together with a date-range filter wider than 14 days it is rejected — see `UNSTABLE_OFFSET_PAGINATION` in the "Errors" section |
| `select` | string[] | — | Field selection: `["id", "title", "type"]` |
| `autoWindow` | boolean | `true` | Split the result set into weekly windows when filtering by a date range wider than 14 days. `false` disables splitting |
| `scope` | string | — | Internal landing area: `KNOWLEDGE` / `GROUP` / `MAINPAGE`. Without the parameter, regular landing sites are returned. Accepted at the top level of the body (`"scope": "KNOWLEDGE"`) or inside `filter.scope` — both forms produce the same request to Bitrix24 |

> **Type filter and area (`scope`).** Bitrix24 binds `filter.type` to the current area — the default area exposes only `PAGE` / `STORE` / `SMN` / `VIBE`. If you filter `{"filter": {"type": "KNOWLEDGE"}}` or `"GROUP"` and do **not** pass `scope`, Vibecode supplies the matching area itself (`type=KNOWLEDGE` → `scope=KNOWLEDGE`), and the search returns exactly the knowledge bases / group pages. An explicit `scope` wins. If the type is given as a list/operator (`{"type": {"$in": ["KNOWLEDGE", "PAGE"]}}`), where a single area cannot be chosen, `meta.warnings` carries a hint with code `TYPE_REQUIRES_SCOPE`. `MAINPAGE` is an area, not a site type (its sites have type `VIBE`), so it is not derived from the filter.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/search" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "type": "PAGE", "active": true },
    "limit": 10,
    "select": ["id", "title", "type", "active"]
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/search" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "type": "PAGE", "active": true },
    "limit": 10,
    "select": ["id", "title", "type", "active"]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { type: 'PAGE', active: true },
    limit: 10,
    select: ['id', 'title', 'type', 'active'],
  }),
})

const { success, data, meta } = await res.json()
console.log('Found:', meta.total)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { type: 'PAGE', active: true },
    limit: 10,
    select: ['id', 'title', 'type', 'active'],
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `data` | array | Array of sites with key fields |
| `meta.total` | number | How many records matched the filter |
| `meta.hasMore` | boolean | Whether there is a next page |
| `meta.durationMs` | number | Request duration in milliseconds |
| `meta.autoWindowed` | boolean | `true` if the result set was split into time windows |
| `meta.windowCount` | number | Number of windows. Present with `autoWindowed: true` |
| `meta.batchWaves` | number | Number of parallel request waves. Present with `autoWindowed: true` |

The `meta` fields sit next to `data`, not inside it. Pages must be walked by `meta.hasMore`: a `data` length equal to `limit` does not rule out the last page.

The URL of any site from the `data` array is its `id`:

```
https://<portal>.bitrix24.com/sites/site/<id>/
```

`<portal>` is the Bitrix24 account domain. Access is restricted by the employee's permissions in Bitrix24.

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 157,
      "title": "Promo landing",
      "code": "/promo/",
      "type": "PAGE",
      "active": true,
      "domainId": 5,
      "createdById": 1,
      "dateCreate": "12.09.2024 10:23:14",
      "dateModify": "04.11.2025 08:51:20"
    }
  ],
  "meta": {
    "total": 10,
    "hasMore": false,
    "durationMs": 99
  }
}
```

With a date-range filter wider than 14 days, `meta` additionally returns `autoWindowed`, `windowCount`, and `batchWaves`:

```json
{
  "success": true,
  "data": [ /* ... */ ],
  "meta": {
    "total": 2,
    "hasMore": false,
    "autoWindowed": true,
    "windowCount": 339,
    "batchWaves": 4,
    "durationMs": 3136
  }
}
```

## Error response example

403 — no scope:

```json
{
  "success": false,
  "error": {
    "code": "SCOPE_DENIED",
    "message": "This endpoint requires 'landing' scope"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNSTABLE_OFFSET_PAGINATION` | `offset` greater than zero together with a date-range filter wider than 14 days. Two different retrieval algorithms produce inconsistent results, so the request is rejected. Take everything in a single request with `limit` up to 5000, or pass `autoWindow: false` with sorting by `id`, or split the date range into parts yourself |
| 403 | `SCOPE_DENIED` | The API key does not have the `landing` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## Known specifics

**Time-window splitting.** A date-range filter wider than 14 days is automatically split into weekly windows executed in parallel waves, so the result set bypasses the ceiling of 5000 records per call. `meta` then returns `autoWindowed: true`, the number of windows `windowCount`, and the number of waves `batchWaves`. The `autoWindow: false` parameter disables splitting. While splitting is active, an `offset` greater than zero is rejected with `UNSTABLE_OFFSET_PAGINATION`.

**Visibility by user permissions.** The search returns only the sites the API key owner has "view" permission for. If a result is expected but `data` is empty, check the user's permissions.

**Deleted sites.** Excluded by default. To include them in the result, pass `{"filter": {"deleted": "Y"}}`. Values are `Y` or `N`.

**Pagination via `offset` is supported.** Vibecode returns the requested `[offset, offset + limit)` window. The `meta.total` value is the exact number of records matching the filter, and `meta.hasMore` shows whether there are records beyond the window.

**Sorting.** The `sort` field in the body: `{"sort": "-id"}` — descending, `{"sort": "id"}` — ascending (the `order` alias is also accepted). Without the parameter — ascending by `id`.

## See also

- [List sites](/docs/entities/sites/list) — GET request with query parameters (for simple filters)
- [Get site](/docs/entities/sites/get) — data of a single site by ID
- [Filtering syntax](/docs/filtering)
- [Batch](/docs/batch) — combining several searches into one request
- [Limits and optimization](/docs/optimization) — rate limits
