It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Move page to new parent with Confluence Cloud REST API

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?

 

2 answers

1 accepted

2 votes
Answer accepted

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 Feb 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

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

Dear rdwyer@metabolon.com ,

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

Thanks for taking a look.

Like # people like this
Supreet Atlassian Team Jul 03, 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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

5,345 views 4 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you