I am in the process of building a workaround for a Confluence bug where relative links inside page trees don’t get updated when using the Copy Page Hierarchy REST endpoint, but rather point back to the original page tree.
For the workaround, I am manually updating the links by using a PUT request, to which I supply the updated content in storage format. I have discovered that this request often fails, with the following error message:
{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: Content body cannot be converted to new editor format"}
Here is an example how to reproduce the issue:
- Create a Confluence page with a link to another page, without specifying a custom link text:
- Try to update the page using the REST API, providing its unmodified content:
fetch('https://cdauth.atlassian.net/wiki/rest/api/content/1459650708', {
method: 'put',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify({
id: "1459650708",
type: "page",
title:"asdf2 Page 5",
body: {
storage: {
value: "<p><ac:link ac:card-appearance=\"inline\"><ri:page ri:content-title=\"asdf2 Page 4\" ri:version-at-save=\"15\" /><ac:link-body>asdf2 Page 4</ac:link-body></ac:link> </p>",
representation: "storage"
}
},
version: {
number: 2
}
})
}).then((res) => res.json()).then((res) => console.log(res))
The page can be edited without problems, but it cannot be updated using the REST endpoint with the storage format, at least as long as the link remains part of the page content.
The error only occurs with certain items in the page content. Removing the link from the above page makes the error go away.
I cannot think of a good workaround for this problem.