## Move a block

`POST /v1/pages/:pageId/blocks/:blockId/move`

Moves a block to another page or to another position on its own page, keeping the block ID.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `pageId` (path) | number | yes | Page ID. List: [`GET /v1/pages`](/docs/entities/pages/list) |
| `blockId` (path) | number | yes | ID of a block in the draft of page `pageId`. List: [`GET /v1/pages/:pageId/blocks`](/docs/entities/pages/blocks/list) without the `version` parameter. For a block from another page, a block in the trash or an ID from the published version, the response is `404` |
| `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 |
|------|-----|:-----:|----------|
| `toPageId` | number | yes | ID of the page the block moves to. List: [`GET /v1/pages`](/docs/entities/pages/list). The page may belong to another site. Pass `pageId` to reorder the block within its own page |
| `afterBlockId` | number | no | ID of the block on page `toPageId` after which the block is placed. List: [`GET /v1/pages/:pageId/blocks`](/docs/entities/pages/blocks/list). Without the field, the block is placed last on the page |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/pages/2417/blocks/29459/move" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"toPageId": 2419}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/pages/2417/blocks/29459/move" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"toPageId": 2419}'
```

### JavaScript — personal key

```javascript
const response = await fetch("https://vibecode.bitrix24.com/v1/pages/2417/blocks/29459/move", {
  method: "POST",
  headers: {"X-Api-Key": "YOUR_API_KEY", "Content-Type": "application/json"},
  body: JSON.stringify({"toPageId": 2419}),
})
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/2417/blocks/29459/move", {
  method: "POST",
  headers: {"X-Api-Key": "YOUR_APP_KEY", "Authorization": "Bearer USER_SESSION_TOKEN", "Content-Type": "application/json"},
  body: JSON.stringify({"toPageId": 2419}),
})
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.blockId` | number | ID of the moved block. Matches `blockId` from the request |
| `data.pageId` | number | ID of the page that now holds the block |

## Response example

```json
{
  "success": true,
  "data": {
    "blockId": 29459,
    "pageId": 2419
  }
}
```

## Error response example

400 — the body has no `toPageId`:

```json
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_FIELDS",
    "message": "toPageId is required."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `MISSING_REQUIRED_FIELDS` | `toPageId is required.` — the body has no `toPageId` |
| 400 | `INVALID_PARAMS` | `Destination ids must be positive safe integers.` — `toPageId` or `afterBlockId` is not a positive integer |
| 400 | `INVALID_PARAMS` | `afterBlockId must belong to the destination page.` — block `afterBlockId` is not on the page that receives the block |
| 400 | `INVALID_PARAMS` | `Path ids must be positive safe integers.` — `pageId` or `blockId` is not a positive integer |
| 400 | `INVALID_PARAMS` | `Body must be a JSON object.` — the body is not a JSON object |
| 400 | `INVALID_PARAMS` | `Unsupported body field.` — the body contains a field that is not in the Request fields (body) table |
| 400 | `FST_ERR_CTP_EMPTY_JSON_BODY` | The `Content-Type: application/json` header is sent with an empty body. Send a body with `toPageId` |
| 400 | `INVALID_SCOPE` | `scope must be KNOWLEDGE, GROUP or MAINPAGE, or omitted.` — `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 404 | `ENTITY_NOT_FOUND` | `Blocks not found on this page.` — the block is not in the draft of page `pageId`: it belongs to another page, is in the trash, was deleted, the ID comes from the published version, or page `pageId` does not exist. The IDs of such blocks are listed in `error.blockIds` |
| 404 | `ENTITY_NOT_FOUND` | `Page or block not found.` — page `toPageId` does not exist |
| 422 | `BITRIX_NO_EFFECT` | `Bitrix24 returned an invalid block descriptor; the action cannot be confirmed.` — Bitrix24 returned a block descriptor that could not be parsed |
| 422 | `BITRIX_NO_EFFECT` | `Bitrix24 did not return the expected block id.` — Bitrix24 did not return a block ID or returned an ID other than `blockId` |
| 422 | `BITRIX_NO_EFFECT` | `Block destination could not be confirmed.` — after the write, the block was not found on page `toPageId` |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the action. The error text comes from Bitrix24 |
| 403 | `SCOPE_DENIED` | The API key does not have the `landing` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only. The request is rejected before Bitrix24 is called |
| 403 | `BITRIX_ACCESS_DENIED` | The Bitrix24 user the key is issued for has no permission to edit the page |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `INVALID_API_KEY` | The key in `X-Api-Key` is not found or has been revoked |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is not available on the Bitrix24 account |
| 409 | `PORTAL_ADDRESS_CHANGED` | A self-hosted 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, returned a server error, or sent a response larger than 8 MiB |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time |

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

## Known specifics

- **A failure after the write does not cancel the move.** Responses `422 BITRIX_NO_EFFECT`, `429`, `502` and `503` do not mean that the block stayed in place. Before retrying, re-read the blocks of the source page and of page `toPageId` with [`GET /v1/pages/:pageId/blocks`](/docs/entities/pages/blocks/list).
- **The call changes the drafts of the source page and of page `toPageId`.** Site visitors see the change after both pages are published with `POST /v1/pages/:id/publication`. See [Pages](/docs/entities/pages) for details.

## See also

- [Copy a block](/docs/entities/pages/blocks/copy)
- [Move a block up](/docs/entities/pages/blocks/up)
- [Move a block down](/docs/entities/pages/blocks/down)
- [List page blocks](/docs/entities/pages/blocks/list)
- [Pages](/docs/entities/pages)
- [Errors](/docs/errors)
