Move page to new parent with Confluence Cloud REST API

Deleted user February 20, 2019

I'm trying to move pages programatically from one place in the hierarchy to another.  Some claim this can't be done and others claim to have done it with something like this;

 


url = "https://foobar.atlassian.net/wiki/rest/api/content/1147126"

payload = json.dumps(

{"id":1147126,
"type":"page",
"title":"My page 8",
"ancestors":[{"id":1378762}],
"space":{"key":"CD"},
"version":{"number":4}})

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

r = requests.request("PUT", url, data=payload, headers=headers, auth=auth)

print(r.ok , r.status_code , r.reason, r.url)

jl = json.loads(r.text)
jl

 

When I run this, I get:

True 200 OK https://foobar.atlassian.net/wiki/rest/api/content/1147126

 

But, in fact, the page is still in the same place when I refresh.

Can anybody help?

 

3 answers

1 accepted

2 votes
Answer accepted
Deleted user February 20, 2019

After expending several hours with experiments, I got it to work, sort of. 

The title has to be changed.  

payload = json.dumps(

{"id":1147126,
"type":"page",
"title": "new page 8",
"ancestors":[{"id":1378762}],
"space":{"key":"CD"},
"version":{"number":4}})

Then the version number can be bumped, and the title can be changed back.

payload = json.dumps(

{"id":1147126,
"type":"page",
"title":"My page 8",
"ancestors":[{"id":1378762}],
"space":{"key":"CD"},
"version":{"number":5}})

It's not how I would have designed it.

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 21, 2019

I remember - the version need to be increased manually - I expected this to be done automatically like when you update a page with the browser ...

Like Zak Laughton likes this
Deleted user February 21, 2019

The version must be increased TWICE.

In my one week's experience with the REST API, it appears to me that it is ALWAYS necessary to get the page, extract the version, and increase the version in any update.

Like Zak Laughton likes this
1 vote
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2019

Dear @[deleted] ,

at first view the request seems fine. Content update with a new ancestors id. Consider following:

  • check permission or page restrictions
  • get full content first and update the ancestors id only, then PUT again
  • could be a bug (search at https://jira.atlassian.com)

So long

Thomas

Deleted user February 20, 2019

Thanks for taking a look.

Like # people like this
Supreet
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 3, 2019

Folks, I was able to replicate the issue and created a bug: https://jira.atlassian.com/browse/CONFCLOUD-67046

Meanwhile I would recommend you to try using the workaround of changing page title

0 votes
Craig Anderson January 6, 2023

There seems to be a (new?) API to move a page in the hierarchy: Move Position 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events