Create Confluence Page using Java API

Hello, I would like to create confluence page using Java code.
I tried pageService / pageManager / draftManager / serviceCommand from
https://docs.atlassian.com/confluence/5.10.0/
But no solution is working.
I have a content which I can save into logged-in user drafts as a regular draft with content (visible in edit mode after open draft in confluence), but there is no way how to save a draft to new page from java code.
If anybody knows how to create regular confluence page with ID and with content (i do not mean title, but regular contentBody) / or save existing draft into new page,
Please tell me.
P.S. without using REST API I would like to do it with JAVA / Confluence API

something like

parentPage = pageManager.getPage(pageId);
myPage = new Page();
myPage.setTitle("My Awesome Page");
myPage.setSpace(parentPage.getSpace());
myPage.setContent("My body content goes here");
pageManager.saveContentEntity(myPage, null);
parentPage.addChild(myPage)
pageManager.saveContentEntity(parentPage, null);
3 Likes

This is not working while content is not simple string, but formated content - with standart confluence HTML tags.

then get the rendered content and use something like

myPage.setBodyAsString(VelocityUtils.getRenderedTemplate("new-page-content.vm", contextMap));