Trashed items missing history in REST API

There seems to be a problem reporting content versions of trashed pages, which in most cases makes the most recent version unavailable to be restored.

To restore a trashed item, we need a version number. That info is unavailable from GET /wiki/rest/api/content?status=any, but we can do:

GET /wiki/rest/api/content/{id}/version

…and already there’s a problem. If there has only ever been one version of the page before it was trashed, the results array is empty.

But, assuming we get results, we can grab the .number from the first (newest) one, and then:

POST /wiki/rest/api/content/{id}/version
{
  "operationKey": "restore",
  "params":{"versionNumber": 123, "message": "", "restoreTitle": true}
}

This revives a version of the item, but its status is still “trashed”. So, from the response, we grab .content.type, .content.title, and increment .number so that we can:

PUT /wiki/rest/api/content/{id}
{
  "version": { "number": 345 },
  "type": "page",
  "title": "trashed page title",
  "status": "current"
}

That’s all well and fine, except the most recent version listed from the first call (content/{id}/version) is a revision behind the latest actual version of the document. And, as mentioned earlier, if there has only been one version, content/{id}/version returns an empty list. (An off-by-one bug, maybe?)

The plot thickens: In that empty-results case (and only then, as far as we can tell) we can revive the latest (and only) version of the document, by magically pulling the number 2 out of thin air:

PUT /wiki/rest/api/content/{id}
{
  "version": { "number": 2 },
  "type": "page",
  "title": "trashed page title",
  "status": "current"
}

None of this would matter if the version information was available when listing content, but trashed items have their version properties hidden. That seems like a conscious choice, which is inconvenient but makes sense. Not listing the newest version, however, feels like a bug, and we have not figured out a workaround. (Except the gross hack for the single-version case.)

Are we misusing the …/version endpoint? Have we misunderstood how to un-trash an item via API? In the UI, the most recent version can be recovered, so something seems off.

Thanks in advance!

1 Like