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

Gadi Tabak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 18, 2020

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
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2020

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

Gadi Tabak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 19, 2020

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
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 19, 2020

You're welcome!

Naveen Kumar_Appfire
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.
November 18, 2021

Hi ,

Could you please share the piece of code on how you update the confluence page.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events