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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Append content with Python to an existing Wiki Page via REST API

I'm trying to append content to an existing confluence wiki page. So far, I can see only PUT exists and it overwrites the whole page.

I also tried to pull the existing content, then append the changes automatically locally and then push again but for some reason, all the emojis/icons replaced with a blue star...

Extract data for edit:

response = requests.get("https://<compnay>.atlassian.net/wiki/rest/api/content/" + page_id + "?type=blogpost&start=0&limit=10&expand=body.view",
auth=(email, apitoken), verify=False)

The PUT code example:

new_headers = {
'Content-Type': 'application/json',
}

data = r'{"id":"' + page_id + '",' \
'"type":"page",' \
'"title":"' + page_title + '",' \
'"space":{"key":"' + workspace + '"},' \
'"body":{"storage":' \
'{"value":"' \
'' + full_code + '<p />",' \
'"representation":"storage"}},"version":{"number":' + str((int(version_number) + 1)) + '}}'

response = requests.put('https://<company>.atlassian.net/wiki/rest/api/content/'+page_id, headers=new_headers,
data=data, auth=(email, apitoken))

Which brings up 2 questions:

More Important: How is it possible to append content to an existing wiki page, without overwriting or deleting the existing content within it?
Less Important: Why the emojis changed to blue star? How can I avoid it?

1 answer

1 accepted

0 votes
Answer accepted

Hi! 

@Gadi Tabak  could you fetch in  &expand=body.storage instead of 

&expand=body.view

 ?

Then you can do concatenation and push data.

I hope next example will help you

https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/confluence.py#L1217

https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/confluence.py#L1276

 

Cheers,

Gonchik

Well, it seems I was checking body.view instead of body.storage the whole time. This is the source to my mistake.

What I eventually did is to fetch the data from body.storage, then manipulated it with re Python library and sent it again to modify the page.

 

Thank you Gonchik for giving me this lead.

Like Gonchik Tsymzhitov likes this

You're welcome!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

82 views 0 3
Read article

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