## Change block text and images

`PATCH /v1/pages/:pageId/blocks/:blockId/nodes`

Changes the content of a page block's nodes: text, images and links.

## 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 on this page. List: [`GET /v1/pages/:pageId/blocks`](/docs/entities/pages/blocks/list) |
| `scope` (query) | string | no | Site area: `KNOWLEDGE` — knowledge base, `GROUP` — workgroup pages, `MAINPAGE` — main pages. Omit the parameter for pages of all other sites |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `nodes` | object | yes | A "selector → value" object with at least one pair. A selector is `.class` or `.class@N`, where `N` is a zero-based index among the nodes with this class. Without `@N` the value is written to every node with this class. The available selectors and the type of each node are in the `nodes` field of the [`GET /v1/pages/:pageId/blocks/:blockId/content`](/docs/entities/pages/block-content) response |
| `nodes.<selector>` — text node | string \| integer \| object | — | A string, an integer, or an object `{"text": "…"}` with a string or an integer in `text`. A fractional number is rejected |
| `nodes.<selector>` — image | object | — | `src` — image URL, `alt` — alternative text. The URL of your own image is returned in the `data.url` field of the [Upload an image to a block](/docs/entities/pages/block-files) method |
| `nodes.<selector>` — link | object | — | `href` — link URL, `text` — link text, `target` — where to open the link, `_blank` opens a new tab |

An empty object or an empty array is not accepted as a value. The keys `attrs`, `dynamicState`, `dynamicBlock` and `dynamicParams` are accepted neither as a selector nor inside a value.

Values for an image and for a link:

```json
{
  "nodes": {
    ".landing-block-node-img": { "src": "https://cdn.example.com/landing/2e8/pixel.png", "alt": "Cover" },
    ".landing-block-node-button": { "href": "https://example.com/sale", "text": "Buy now", "target": "_blank" }
  }
}
```

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/pages/42/blocks/7/nodes" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "nodes": {
      ".landing-block-node-title": "Spring sale"
    }
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/pages/42/blocks/7/nodes" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "nodes": {
      ".landing-block-node-title": "Spring sale"
    }
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/pages/42/blocks/7/nodes', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    nodes: {
      '.landing-block-node-title': 'Spring sale',
    },
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/pages/42/blocks/7/nodes', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    nodes: {
      '.landing-block-node-title': 'Spring sale',
    },
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data.id` | number | Block ID |
| `data.pageId` | number | Page ID |
| `data.anchor` | string | Block anchor. An automatic anchor has the form `b<id>`, for example `b7` |
| `data.content` | string | The full block HTML, read back after the change |
| `data.nodes` | object | Empty object. The block state is in `content` |
| `data.styles` | object | Empty object. The block state is in `content` |
| `data.attrs` | object | Empty object. The block state is in `content` |
| `data.cards` | object | Empty object. The block state is in `content` |
| `data.active` | boolean | Whether the block is active |

## Response example

The paragraph text in `content` is shortened with an ellipsis, and the markup is unchanged.

```json
{
  "success": true,
  "data": {
    "id": 7,
    "pageId": 42,
    "anchor": "b7",
    "content": "<div id=\"block7\" data-id=\"7\" class=\"block-wrapper block-27-one-col-fix-title-and-text-2\"><section class=\"landing-block js-animation g-pt-30 g-pb-30\">\r\n\t<div class=\"landing-block-node-text-container container g-max-width-container\">\r\n\t\t<h2 class=\"landing-block-node-title js-animation fadeIn g-mb-20 g-color\">Spring sale</h2>\r\n\t\t<div class=\"landing-block-node-text js-animation g-mb-20 g-pb-1 g-color\">\r\n\t\t\tSed feugiat porttitor nunc, non dignissim ipsum vestibulum in. …\r\n\t\t</div>\r\n\t</div>\r\n</section></div>",
    "nodes": {},
    "styles": {},
    "attrs": {},
    "cards": {},
    "active": true
  }
}
```

## Error response example

400 — a text node received an object without a `text` field:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Text nodes require a string, integer or an object with text"
  }
}
```

## Errors

| HTTP | Code | Marker in `error.message` | Description |
|------|-----|--------------------------|----------|
| 400 | `INVALID_PARAMS` | `pageId and blockId must be positive safe integers` | `pageId` or `blockId` is not a positive integer |
| 400 | `INVALID_SCOPE` | `scope must be KNOWLEDGE, GROUP or MAINPAGE` | `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 400 | `MISSING_REQUIRED_FIELDS` | `Required fields: nodes` | The body has no `nodes` field |
| 400 | `MISSING_REQUIRED_FIELDS` | `A JSON object is required` | The body is not a JSON object |
| 400 | `MISSING_REQUIRED_FIELDS` | `nodes must be a non-empty selector map` | `nodes` is an empty object or not an object |
| 400 | `INVALID_PARAMS` | `Unexpected body field` | The body has a field other than `nodes` |
| 400 | `INVALID_PARAMS` | `Selectors must be .class or .class@N` | A selector is not in the `.class` or `.class@N` format, including the service key `attrs` in place of a selector |
| 400 | `INVALID_PARAMS` | `Service node fields are not accepted` | The value object has an `attrs`, `dynamicState`, `dynamicBlock` or `dynamicParams` key |
| 400 | `INVALID_PARAMS` | `Node values must not be empty objects or arrays` | The value is an empty object or an empty array |
| 400 | `INVALID_PARAMS` | `Each node value must be a string, integer, object or array` | The value is a fractional number, `null` or a boolean |
| 400 | `INVALID_PARAMS` | `Text nodes require a string, integer or an object with text` | The text node value is neither a string, an integer, nor an object with a string or an integer in `text` |
| 400 | `INVALID_PARAMS` | `Unknown selector or index. Available selectors: …` | The block has no such selector, or the `@N` index exceeds the number of nodes with this class. The message lists the available selectors |
| 401 | `TOKEN_MISSING` | — | The API key has no Bitrix24 access tokens |
| 403 | `SCOPE_DENIED` | — | The key has no `landing` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | — | The key is read-only. The request is rejected before the Bitrix24 account is called |
| 404 | `ENTITY_NOT_FOUND` | `Page or block not found` | The page does not exist, the block does not exist, or the block belongs to another page |
| 404 | `ENTITY_NOT_FOUND` | — | The change was accepted, but the block could not be read back after it |
| 409 | `LANDING_MODULE_NOT_ENABLED` | — | The Sites module is not enabled on the Bitrix24 account |
| 409 | `PORTAL_ADDRESS_CHANGED` | — | A self-hosted Bitrix24 portal moved to a new address, but the key's webhook was issued for the old one. Reissue the key's webhook |
| 422 | `BITRIX_ERROR` | `Bitrix24 did not confirm the block operation` | Bitrix24 did not confirm the block change |

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

## Known specifics

- **Scripts and event handlers are neutralized without an error.** The string `Hi<script>alert(1)</script><b onclick="x()">bold</b>` gets a `200` response but is saved modified: `Hi<sc ript="">alert(1)<b oncl="" ick="x()">bold</b></sc>`. `script` tags and `on*` attributes stop working, and the text stays on the page in modified form. Check what was actually saved in `data.content`.

## See also

- [Upload an image to a block](/docs/entities/pages/block-files)
- [Change block styles](/docs/entities/pages/block-styles)
- [Change block attributes](/docs/entities/pages/block-attrs)
- [Change a block node tag](/docs/entities/pages/block-tags)
- [Set a block anchor](/docs/entities/pages/block-anchor)
- [Publish a block](/docs/entities/pages/block-publication)
- [Read block content](/docs/entities/pages/block-content)
- [List page blocks](/docs/entities/pages/blocks/list)
- [Pages](/docs/entities/pages)
