Move Page Confluence Rest API

Bart Kerfeld August 13, 2015

I am looking for a way to move pages using the Confluence Rest API. I would like to be able to both move the location of the page within a space and move the page to another space with a specified parent. It would be nice if there was a simple command to do this, otherwise the following could also work.

//sample code: don't get got up in the syntax just look at it for the concept.
public void MovePage(string pageName, string spaceKey, string newSpaceKey, string newParentName)
{
	string body = GetPageBody(pageName, spaceKey);
	List<string> labels = GetPageLabels(pageName, spaceKey);
	List<File> files = GetPageAttachments(pageName, spaceKey);
	try 
	{
		CreatePage(pageName, newSpaceKey, newParentName);
		AddLabels(labels);
		UploadFiles(files);
		UpdatePage(body);
		PurgePage(pageName, spaceKey);
	} catch (Exception)
	{
		// do something if it breaks.
	}

}

What's preventing me from doing this second option is I cannot find a way to AddLabels or DownloadAttachments using any of the remote libraries. I have been able to figure out how to implement every other function.

Looking at the REST API documentation I have found this for adding labels

image2015-8-13 13:48:1.png

image2015-8-13 13:49:3.png

so i tried the following:

curl -u username:password -X POST 'Content-Type: application/json' -d '{"prefix":"global","name":"label"}' http://base_url/rest/api/content/PAGEID/label

Sadly, it did not work.

As for downloading files, I could not find anything in the REST API. However, I did discover when hovering over an attachment in my wiki that this URL format allows me to download the file:

http://base_url/download/attachments/PAGEID/FILENAME?api=v2

This makes me think that there is some sort of http request I can make to grab the file contents but I have yet to figure it out.

The language I am doing this in is c# however if you have a solution that does this in any language or via a simple cURL command, I would love to see it.

Thanks!

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Arjun Shukla May 18, 2017

Not REST api, but a work around I put together.

Try this:

To move a page as child page

curl -X GET \
'<your-confluence-URL>/pages/movepage.action?pageId=<page-to-be-moved-pageId>&spaceKey=<target-space-key>&targetTitle=<target-title-of-parent-page>&position=append' \
-H 'authorization: Basic <encoded-username-password>' \ 
-H 'x-atlassian-token: no-check'


To move a page as top level page in space

curl -X GET \
'<your-confluence-base-URL>/pages/movepage.action?pageId=<page-to-be-moved-pageId>&spaceKey=<target-space-key>&position=topLevel' \...


ksuzuki May 31, 2017

@arjun - In  your first example "To move a page as a child page", is there any way to specify the new parent page? I'm trying to move thousands of pages within a space to a different parent page.

Arjun Shukla June 22, 2017

Hi Ken,

The targetTitle is where you must specify the new parent page title.

Regards,

Arjun

Deleted user February 18, 2019

<encoded-username-password>

Dumb question: encoded how?  Is this the same as the API token?  I think not.

 

The REST API documentation seems to claim you can move to a different parent, but I sure can't make it work.

hsteinmetz April 24, 2019

Is there some documentation on all this?

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2017

Yes, Confluence Command Line Interface (CLI) supports the movePage action which works for pages but not blogs. I still don't think Confluence has a REST API for this sad.

Supreetha Upadhya September 28, 2017

Does this work for moving attachments as well? Thanks!

0 votes
Mike Araya July 19, 2016

I'm also looking for a way to move a page to another wiki space from the REST API.  I tried changing the space.key to a different value in the json data passed with my cURL PUT request, but got a status 400 error: "You can't change an existing page's space.".   I also tried setting the first ancestor to the page ID for a page in a different wiki space, but got a status 500 error: "java.lang.IllegalArgumentException: Can't add a parent from another space."  I'm making cURL PUT requests from python to a Confluence 5.9 server.

If you're using a version prior to 5.5, you might want to take a look at the XML-RPC/SOAP APIs.  There's a "movePageToTopLevel" call that accepts a different space key, but moves it to the top level, instead of under a specified parent.  But once the page is in the new space, you can move it to a parent in the same space by setting the first ancestor node in your json data sent with your PUT request.

Bob Swift CLI also seems to support moving a page.

For the record, I haven't tried either of those.

If you're going to simulate moving a page by creating a copy, then I assume, deleting the original, how will you fix up all the links to the original pages?  When I create copies of pages with cURL GET and POST requests, all of the links to the original pages remain intact.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events