I am attempting to use the Confluence REST API to correct the tree structure of pages on a Confluence site. I can do this manually, however there are quite a few pages and I already have the tree structure in another XML file.
Currently I am able to upload pages and images using the confluence REST API. Definitions are located here.
I have attempted to use the /rest/api/content/{id}
PUT command. This requires the content to be in the body of the request. Attaching the content I had received from a previous GET request I find I have to update the version count.
The above all works. Adding to the ancestor list however doesn't seem to. If I add the parent page to the list of ancestors I get formatting errors reported back.
Added to this if I manually attach the page to another page and request its contents I find that the parent appears twice in the ancestor list. Also the history count does not increase.
The resulting JSON returned from a GET request for the page:
http://someconfluencesite.com/rest/api/content/10031361?expand=ancestors (200)
{
"id" : "10031361",
"type" : "page",
"title" : "Automatic Action Usage Updates",
"ancestors" : [{
"id" : "10031327",
"type" : "page",
"title" : "Action Lists"
}, {
"id" : "10031327",
"type" : "page",
"title" : "Action Lists"
}, {
"id" : "10031328",
"type" : "page",
"title" : "Actions Tab"
}, {
"id" : "10031327",
"type" : "page",
"title" : "Action Lists"
}, {
"id" : "10031327",
"type" : "page",
"title" : "Action Lists"
}, {
"id" : "10031328",
"type" : "page",
"title" : "Actions Tab"
}
]
}
The tree this is for looks like the following:
- Space
- Action Lists
- Actions Tab
- Automatic Action Usage Updates
- Actions Tab
- Action Lists
This leads me to believe I am using the wrong command.
I have attempted to contact Confluence support however their authorization emails are not arriving in my inbox. So I have come here :)
So my question is what is the REST call for creating a page tree in confluence? After that, what is the format of the request body?
Edit: The following PUT request gets a successful return code. Yet the returned object does not have the ancestor attached (not unusual as in all GET requests you have to expand to get it). The version number does not update. The two pages are not hooked to each other either.
{
"id":"10552520",
"type":"page",
"title":"Correct Page Title",
"ancestor":[
{
"id":"10552522",
"type":"page"
}],
"version":
{
"number":"2"
}
}
The nice thing the above does though is delete all the contents of the page.
The following POST call results in the page being created but having no ancestors. The ancestor exists with the id supplied. Strangely this also is created without any content in the page.
{
"type":"page",
"title":"Correct Title",
"space":{"key":"SpaceKey"},
"ancestor":[{"id":"10553655","type":"page"}],
"body":{"storage":{"value":"<p>New Page </p>","representation":"storage"}}
}
Putting the above into the REST API browser also results in the children not being attached to the parent.