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.

Roll back a page to an earlier revision

Every save keeps the revision before it. Find the one that was right and send its id as activeRevision on the page: it is live again at once, with no new revision. Then base the next edit on it with originRevision, or the edit brings back what you rolled back.

Context

Context. An import wrote the wrong text into a hundred pages, or an editor published a change that has to come off now. Nothing is lost: each save made a new revision and kept the old one. Rolling back is making an older revision the live one again, which is a single request per page.

Before you start

Credentials for a backend user who may edit pages, and the page id. To find the revision to go back to, the admin's revision history is the easiest view; the API gives the same list.

Steps

  1. List the revisions: GET /cdna-api/pages/page/1885?properties={id,activeRevision{id},revisions{id,created,name}}. They come oldest first. To see what one holds, the admin's history compares them; through the API, revisions{id,areasContent} returns every revision's content, which is a large answer on an old page.
  2. Send the chosen id as the page's activeRevision, at the top level of the body: {"activeRevision": 3482}.
  3. Check the page signed out.
  4. Base the next edit on the revision you restored: "originRevision": 3482 inside patchRevision. The newer revision you rolled away from is still the newest one, and a patch without an origin copies it.

Code

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

{"activeRevision": 3482}
JSON
{
  "result": "success",
  "data": {
    "id": 1885,
    "activeRevision": {
      "id": 3482,
      "navSection": "API sandbox"
    }
  },
  "message": "The Page has been saved successfully."
}

The real answer on this site's sandbox page, rolling back the change made in Change one area: revision 3483 had set navSection to devdocs, and 3482 is live again with the old value. No revision was created by the rollback.

Other record types roll back in their own ways:

RecordRequest
Pages, books and their units and pages, blog posts, FAQ pages and questions{"activeRevision": <id>} on the record's edit route
Custom entity recordsThe same, or PUT /cdna-api/custom-entities/activate-revision/{record}/{revision}
FormsPUT /cdna-api/forms/activate-form-revision with revision_id

Why this and not that

Not a new edit that types the old content back: it makes a third revision holding only what you remember to copy across, and takes longer. Not deleting the bad revision: no API route deletes a page's revision, and the rollback does not need it gone. Not a rollback through patchRevision: inside a patch, activeRevision is true or false, about the new revision; the id goes at the top level. And the rollback changes content only: published is separate, so a page that was unpublished stays unpublished.

Go deeper

Was this page helpful?

Your answer goes to the docs team.