How-to library · Developer docs

How-to library

Task-shaped pages: a title that starts with a verb, the situation in a few lines, the steps, the working code in both engines, and why this way rather than another. Found from a search, done, and left.

Change one area of a page without touching the rest

patchRevision copies the live revision and changes only the layout areas you name. Send originRevision, the layout area as areaContent(name), and activeRevision: true inside the patch: the change goes live in one request, and every other area, collections included, stays as it was.

Context

Context. An integration needs to change one thing on a page: a price in a text area, a banner switch, a date. The page has other areas, and a component collection full of sections, that the integration knows nothing about and must not disturb. A page's content lives in revisions, so the change is a new revision; the question is how to make one that differs from the live one in a single area.

Before you start

The page id, the layout area's name and its input type, from the layout (Writing areas has the value each input type takes), and credentials for a backend user who may edit pages.

Steps

  1. Read the live revision's id: GET /cdna-api/pages/page/1885?properties={id,activeRevision{id}}.
  2. Send a PUT with patchRevision: originRevision set to that id, "activeRevision": true, and the layout area as "areaContent(name)": value. Several areas can go in the same patch.
  3. Ask for the new revision and the layout area in the same request, with properties, so the answer shows what was saved.
  4. Check the page signed out. A layout area in a component inside a collection is changed with patchAreaCollectionElement, not with areaContent.

Code

HTTP
PUT /cdna-api/pages/page/1885?properties={id,activeRevision{id,navSection:areaText(navSection)}}
Content-Type: application/json

{
  "patchRevision": {
    "originRevision": 3482,
    "activeRevision": true,
    "areaContent(navSection)": "devdocs"
  }
}
JSON
{
  "result": "success",
  "data": {
    "id": 1885,
    "activeRevision": {
      "id": 3483,
      "navSection": "devdocs"
    }
  },
  "message": "The Page has been saved successfully."
}

That is the real answer on this site's sandbox page. Read again, revision 3483 still had all five sections of the page's collection, the image in one of them included: only navSection had changed.

Why this and not that

Not revisions: it makes a revision holding exactly the layout areas you send, so every layout area you leave out, the whole collection included, is empty in it (Choosing a write). Not a patch without originRevision: it copies the newest revision rather than the live one, and after a rollback that brings back the content the rollback removed. Not "activeRevision": true beside patchRevision: at that level the key takes a revision id, and true is a 422 "expecting an id"; inside the patch it makes the new revision live. And not an edit with no activation at all, which saves a revision nobody sees.

Go deeper

Was this page helpful?

Your answer goes to the docs team.