## Update block attributes

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

Changes the attributes of block nodes on a site page, for example the countdown end date of a timer block. Only attributes that the block manifest declares as editable can be changed.

## 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` — home pages. Omit the parameter for pages of all other sites |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `attrs` | object | yes | An object of the form "selector → attributes". Must not be empty. The body has no other fields |
| `attrs.<selector>` | object | yes | The key is a node selector `.class` or `.class@N`, where `N` is a zero-based index among the nodes with that class. Without `@N`, the change applies to all nodes with that class. Only nodes for which the block manifest declares editable attributes are allowed. They are visible in the response of [`GET /v1/pages/:pageId/blocks/:blockId/content`](/docs/entities/pages/block-content): elements with the `attribute` key in the `cards`, `style` and `attrs` fields, and for a timer block — `cards.<selector>.additional.attrs`. The value is a non-empty object of attributes |
| `attrs.<selector>.<attribute>` | string | yes | The new attribute value. For a timer block, `data-end-date` is the countdown end time in milliseconds |

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/pages/42/blocks/7/attrs" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "attrs": {
      ".landing-block-node-card@0": {
        "data-end-date": "1798750800000"
      }
    }
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/pages/42/blocks/7/attrs" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "attrs": {
      ".landing-block-node-card@0": {
        "data-end-date": "1798750800000"
      }
    }
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/pages/42/blocks/7/attrs', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    attrs: {
      '.landing-block-node-card@0': {
        'data-end-date': '1798750800000',
      },
    },
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/pages/42/blocks/7/attrs', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    attrs: {
      '.landing-block-node-card@0': {
        'data-end-date': '1798750800000',
      },
    },
  }),
})

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 timer block markup is long, so `content` is shortened: it shows the `.landing-block-node-card` node with the saved attribute, and the rest is replaced with an ellipsis.

```json
{
  "success": true,
  "data": {
    "id": 7,
    "pageId": 42,
    "anchor": "b7",
    "content": "<div id=\"block7\" data-id=\"7\" class=\"block-wrapper block-51-4-countdown-music\">…<div class=\"landing-block-node-card row g-mb-50 js-countdown u-countdown\" data-end-date=\"1798750800000\" data-days-format=\"%D\" data-hours-format=\"%H\" data-minutes-format=\"%M\" data-seconds-format=\"%S\" data-days-expired-classes=\"u-countdown--days-expiried\">…</div>…</div>",
    "nodes": {},
    "styles": {},
    "attrs": {},
    "cards": {},
    "active": true
  }
}
```

## Error response example

400 — the selector is not among the nodes with editable attributes; the message lists the available ones:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Unknown selector or index. Available selectors: .landing-block-node-card"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | The selector is not among the nodes with editable attributes, or the `@N` index exceeds the number of nodes with that class. The message lists the available selectors. For a block without such nodes, the list after `Available selectors:` is empty |
| 400 | `INVALID_PARAMS` | The value for a selector is not an object, or is an empty object |
| 400 | `INVALID_PARAMS` | The selector is not in the `.class` or `.class@N` format. Service keys are not accepted in place of a selector |
| 400 | `INVALID_PARAMS` | The body contains a field other than `attrs` |
| 400 | `INVALID_PARAMS` | `pageId` or `blockId` is not a positive integer |
| 400 | `MISSING_REQUIRED_FIELDS` | The body is not a JSON object, it has no `attrs` field, or `attrs` is an empty object |
| 400 | `INVALID_SCOPE` | `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 404 | `ENTITY_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 afterwards |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is not enabled 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 |
| 422 | `BITRIX_ERROR` | Bitrix24 did not confirm the block change |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only. The request is refused before any call to the Bitrix24 account |
| 403 | `SCOPE_DENIED` | The key does not have the `landing` scope |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 access tokens |

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

## Known specifics

- **An undeclared attribute is dropped without an error.** If the node matches but the attribute is not among those declared in the manifest, the response comes back with `200`, but the attribute is not saved. A request with `data-foo` and `onclick` to the `.landing-block-node-card@0` node of a timer block returned success, and neither attribute appeared in `content`. Verify the result in `content`.

## See also

- [Update block text and images](/docs/entities/pages/block-nodes)
- [Update block styles](/docs/entities/pages/block-styles)
- [Change a block node tag](/docs/entities/pages/block-tags)
- [Read block content](/docs/entities/pages/block-content)
- [List page blocks](/docs/entities/pages/blocks/list)
- [Errors](/docs/errors)
