Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to move a page in Confluence with Python API

Marlene Pirker June 7, 2021

I am trying to copy a page to one space to another INCLUDING the attachments. I works to copy the whole page with this code: 

#I want to easily copy a page from one space to another space
page_id = confluence.get_page_id("MARLENETES", "NewMarlene(1)")
print(page_id)

# retrieve the page, including its content.
page_c = confluence.get_page_by_id(page_id, expand='body.storage')
#print(page_c)

# the body HTML
body = page_c['body']['storage']['value']
print(body)

parent_id = confluence.get_page_id("NB", "halli2")

for i in range(1, 2):
print('new test'.format(i))

# use the same above to retrieve the parent page's id.
confluence.create_page('MARLENETES', 'NewMarlene({})'.format(i), body, parent_id, type='page', representation='storage', editor='v2')
time.sleep(1)

 

But the problem is that any images included in the page are not copied. In stackoverflow I found this answer: https://stackoverflow.com/questions/63061984/how-to-move-confluence-pages-along-with-the-contents-from-one-space-to-another-u

I don't want to accept that it "just doesn't work" with Python. Has anybody solved the problem? 

1 answer

1 accepted

0 votes
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 9, 2021

Hello @Marlene Pirker , 

If I understand correctly you are trying to clone a Confluence page via REST API using the  Atlassian Python API.

Now, if this is correct I can tell you that:

 

In other words, you should be able to make this work by writing the code to run the REST API calls in Python without using the Atlassian Python API.

 

Also, I would like to mention that our developers released a new REST API endpoint to copy a page with all the attachments that I believe it's exactly what you are looking for:

Copy single page

POST /wiki/rest/api/content/{id}/copy

Copies a single page and its associated properties, permissions, attachments, and custom contents....

 

Please review the documentation for the above endpoint and let me know if you have further questions.

 

Cheers,
Dario

Marlene Pirker June 10, 2021

Thank you! I will read the documentation and will reach out if I have further questions.

Like Dario B likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events