Editing pages created via /rest/api/content

Hey everyone,

I have a plugin that creates a new page via /rest/api/content. This is the body data:

    const bodyData = `{
      "title": "${newPageTitle.value}",
      "type": "page",
      "space": {
        "key": "${context.confluence.space.key}"
      },
      "ancestors": [
        {
          "id": "${context.confluence.content.id}"
        }
      ],
      "body": {
        "storage": {
          "value": "<some html here whatever goes>",
          "representation": "storage"
        }
      }
    }`;

The problem here is that the page created this way has a different edit URL which in turn causes the “old” editor to be rendered which doesn’t provide the best user experience. The edit links are as follows:

I’ve redacted some of the values (don’t know if it’s private :D).

My first question is what is the difference between types of body (storage, view, …)? And second, how to get the same editing type? Do I have to add a parameter or something like that?

Thanks in advance

If anyone is interested, the solution is to set metadata.property editor to “v2”.

I’ve done it in the success function of AP.request that creates a new page (POST to /rest/api/content) since the response from that call includes the id of the newly created page. Check out create content property REST documentation

However, I have a feeling this can be all done in the same request as that link says:

Content properties can also be added when creating a new piece of content by including them in the metadata.properties of the request.

but I haven’t managed to find a way to set it when creating new content.

1 Like

Thanks @ChupaCabra

Did you ever figure out how to include in the new content API call?

I am stuck in the same place.

Hey, unfortunately, the current solution is good enough for me for now so I didn’t even try anything else. If I ever get back to this and if I find a solution, I’ll post here again, but I’m not sure when I’ll get back to refactoring it.

This seems to work when hitting the wiki/rest/api/content/ endpoint

{
  "title": "Test Page from API editor v2",
  "type": "page",
  "space": {
    "key": "TS1"
  },
  "status": "current",
  "ancestors": [
    {
      "id": "1239286918"
    }
  ],
  "body": {
    "storage": {
      "value": "Test content",
      "representation": "storage"
    }
  },
  "metadata": {
  	"properties":{
	  	"editor": {
	  		"value": "v2"
	  	}
  	}
  }
}
4 Likes

Indeed it does. Thank you for this

This was a life-saver - thank you!!!