Editor page is blank when creating page via REST API

Hi,

I’ve found that when creating a page via the REST API the page displays correctly, however when pressing the edit button it shows blank content

This is the request I am making

post("/wiki/rest/api/content").header("content-type", "application/json").body([
    title: "${sprintEndDate.format('yyyy-MM-dd')} Retrospective",
    type: "page",
    space: [key: "AB"],
    body: [editor: [ value: JsonOutput.toJson(g), representation: "atlas_doc_format"]],
    metadata: [properties: [editor: [key: "editor", value: "v2"]]]
]).asObject(Map).body

I’d really appreciate someone telling me where I am going wrong here, thanks!

1 Like

@BenDavies,

I’ve tried turning your example into a raw HTTP request (making an assumption that ADF is in g) but I only get 500 response, so the page never exists. I can get a 200 by sending {} as value, but that creates an empty page, which doesn’t seem to be what you are doing.

Can you link to where you’re getting this structure from? In the REST API docs for Create content using POST /wiki/rest/api/content, there are descriptions of the body section. I can’t find editor as one of the known types. Nor can I find atlas_doc_format as a known representation.

@ibuchanan

Thanks for having a look so what I am doing is retrieving the initial content from this REST request

get("/wiki/rest/api/content/${lastRetroPage.id}?expand=body.atlas_doc_format")

I am then altering the ADF result and that is being passed in as g to my next request

I’ve been trying a variety of combinations to try and get the edit page to display

editor and atlas_doc_format have been taken from here
https://jira.atlassian.com/browse/CONFCLOUD-68057?focusedCommentId=2363313&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2363313

Thanks!

@BenDavies,

Thanks, undocumented parts of the API are tricky but that was enough to get a plain HTTP request. I get a 200 and my content “survives” into editing.

Here’s the request that I made:

{
    "title": "2021-06-01 Retrospective",
    "type": "page",
    "space": {
        "key": "API"
    },
    "body": {
        "editor": {
            "value": "{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"Some text in a paragraph\"}]}]}",
            "representation": "atlas_doc_format"
        }
    },
	"metadata": {
        "properties": {
            "editor": {
                "key": "editor",
                "value": "v2"
            }
        }
    }
}

That leaves me to suspect your JsonOutput.toJson(g) might not be valid ADF. By the way, is that Ruby? Do you know if that is properly string encoding the JSON before sending?

Thank you! Using your example I have got it working, it looked like in the last part of my script I was causing troubles with the atlas_doc_format formatting by deleting too many content arrays

I was using Groovy for the script :slight_smile:

2 Likes