Creating a page in the new format from existing content

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?

Dear Benjamin,

as far as I know the editor2 format is only used by Atlassian. I assume you want to create a page which uses the new editor. If yes you have to set property editor: { value:“v2”} when creating the page.

I copied two lines of code form our app which might help:

body: { storage: { value: body, representation: "storage" } },
metadata:  { properties: { editor: { value: "v2" } } },

I hope that helps

Andreas

2 Likes

Thanks for your answer, that works fine. Where is the metadata documented? I couldn’t find it anywhere. Additional question: is there a piece of metadata to generate the document with expanded view (not fixed width)? Thanks.

In case anyone end ups here wondering how to make the created page full-width, I found the solution in this post Make layout full-width when creating page