## Create from a template

`POST /v1/pages/from-template`

Creates a page on a site from a ready-made template, at the site root or in the specified folder. The site and the destination folder are checked before the page is created.

Requires the `landing` scope.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `scope` (query) | string | no | Site type: `KNOWLEDGE` — knowledge base, `GROUP` — workgroup site, `MAINPAGE` — main page. Omit the parameter for pages of other sites |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `siteId` | number | yes | Site ID. List: [`GET /v1/sites`](/docs/entities/sites/list) |
| `templateCode` | string | yes | Template code — the `code` field. List: [`GET /v1/page-templates`](/docs/entities/page-templates/list) |
| `title` | string | no | Page title. Without the field the page gets the template name, for example "Empty page" for the `empty` template |
| `description` | string | no | Page description |
| `folderId` | number \| null | no | ID of a folder on the `siteId` site. List: [`GET /v1/sites/:id/folders`](/docs/entities/sites/folders/list). `null` or `0` — site root |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/pages/from-template" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"siteId": 3, "templateCode": "empty", "title": "Page from a template"}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/pages/from-template" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"siteId": 3, "templateCode": "empty", "title": "Page from a template"}'
```

### JavaScript — personal key

```javascript
const response = await fetch("https://vibecode.bitrix24.com/v1/pages/from-template", {
  method: "POST",
  headers: {"X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json"},
  body: JSON.stringify({"siteId": 3, "templateCode": "empty", "title": "Page from a template"}),
})
const result = await response.json()
if (!response.ok) throw new Error(result.error.message)
console.log(result.data)
```

### JavaScript — OAuth application

```javascript
const response = await fetch("https://vibecode.bitrix24.com/v1/pages/from-template", {
  method: "POST",
  headers: {"X-Api-Key": "YOUR_APP_KEY", "Authorization": "Bearer USER_SESSION_TOKEN", "Content-Type": "application/json"},
  body: JSON.stringify({"siteId": 3, "templateCode": "empty", "title": "Page from a template"}),
})
const result = await response.json()
if (!response.ok) throw new Error(result.error.message)
console.log(result.data)
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | Always `true` on success |
| `data` | object | The created page |
| `data.id` | number | Page ID |
| `data.siteId` | number | ID of the page's site |
| `data.folderId` | number \| null | Folder ID. `null` — the page is at the site root |
| `data.title` | string | Page title |
| `data.code` | string | Page code in the URL |
| `data.active` | boolean | Whether the page is published |
| `data.deleted` | string | `Y` — the page is in the trash, `N` — it is not |

## Response example

The page is created, HTTP status `201 Created`:

```json
{
  "success": true,
  "data": {
    "id": 2431,
    "siteId": 3,
    "folderId": null,
    "title": "Page from a template",
    "code": "page-from-a-template",
    "active": false,
    "deleted": "N"
  }
}
```

## Error response example

404 — no template with this code:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Template not found; read GET /v1/page-templates for templateCode values."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 404 | `ENTITY_NOT_FOUND` | `Template not found; read GET /v1/page-templates for templateCode values.` — template `templateCode` does not exist |
| 404 | `ENTITY_NOT_FOUND` | `Site not found.` — site `siteId` does not exist |
| 404 | `ENTITY_NOT_FOUND` | `Folder not found in the destination site.` — the `folderId` folder is not on the `siteId` site |
| 404 | `ENTITY_NOT_FOUND` | `Page or folder not found.` — Bitrix24 did not find the page or folder during creation |
| 400 | `MISSING_REQUIRED_FIELDS` | `siteId and templateCode are required; read GET /v1/page-templates for codes.` — `siteId` or `templateCode` is not passed, or `templateCode` is an empty string or not a string |
| 400 | `INVALID_PARAMS` | `Body must be a JSON object.` — the body is not a JSON object |
| 400 | `INVALID_PARAMS` | `Body contains a field this operation does not accept.` — the body contains a field that is not in the request fields table |
| 400 | `INVALID_PARAMS` | `siteId must be a positive safe integer.` — `siteId` is not a positive integer |
| 400 | `INVALID_PARAMS` | `folderId must be a positive safe integer or null for the root.` — `folderId` is not a positive integer, `null` or `0` |
| 400 | `INVALID_PARAMS` | `title must be a string.` — `title` is not a string |
| 400 | `INVALID_PARAMS` | `description must be a string.` — `description` is not a string |
| 400 | `INVALID_SCOPE` | `scope must be KNOWLEDGE, GROUP or MAINPAGE, or omitted.` — `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 422 | `BITRIX_NO_EFFECT` | `Bitrix24 did not confirm the page action.` — Bitrix24 did not return the ID of the created page |
| 422 | `BITRIX_NO_EFFECT` | `Bitrix24 did not return the page after the action.` — the created page could not be read |
| 422 | `BITRIX_NO_EFFECT` | `Bitrix24 did not persist the requested page state.` — the page ended up outside the `siteId` site or outside the `folderId` folder |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the creation. The error text comes from Bitrix24 |
| 403 | `SCOPE_DENIED` | The API key lacks the `landing` scope |
| 403 | `BITRIX_ACCESS_DENIED` | The Bitrix24 user on whose behalf the key was issued has no permission to create the page |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key works in read-only mode. The request is rejected before it reaches Bitrix24 |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is not passed |
| 401 | `INVALID_API_KEY` | The key in `X-Api-Key` is not found or has been revoked |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is not available on the Bitrix24 account |
| 409 | `PORTAL_ADDRESS_CHANGED` | The on-premise Bitrix24 moved to a new address, but the key's webhook was issued for the old one. Reissue the key's webhook |
| 429 | `RATE_LIMITED` | The Bitrix24 request limit is exceeded. Retry the request in 1-2 seconds |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 did not respond or responded with a server error |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond within the allotted time |

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

## See also

- [List page templates](/docs/entities/page-templates/list)
- [Copy a page](/docs/entities/pages/copy)
- [List folders](/docs/entities/sites/folders/list)
- [Pages](/docs/entities/pages)
