I’m trying to create a new page in Confluence with some content retrieved from some other page, which is in the new format. I retrieved the body from the existing page and tried to pass it as body of the new page, but the created page seems to be in the legacy format. I’m not sure how body formats work to be honest, I find it pretty confusing. I tried multiple representations but either the page ends up in the legacy format or it is created with no content at all. Here is the version I’m using for now, which creates the page in the legacy format:
// Retrieve the existing page.
const contentResponse = await api.asApp().requestConfluence('/wiki/rest/api/content/46759939?type=page&expand=body.storage', {
headers: {
'Accept': 'application/json'
}
});
const value = JSON.stringify(json.body.storage.value);
// Create the new page.
const bodyData = `{
"title": "Foobar,
"type": "page",
"space": {
"key": "FOO"
},
"status": "current",
"body": {
"editor2": {
"value": ${value},
"representation": "editor2"
}
}
}`;
const response = await api.asApp().requestConfluence('/wiki/rest/api/content', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
});
I’m pretty sure I’m completely missing the point of page formats but I can’t find any documentation on this. What am I doing wrong?