Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to modify a codeblock using the confluence python api

Harry
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 25, 2022

Hi, currently I have a yaml format code block on a confluence page, I'm trying to update this as part of a python project using the confluence python api, so far I've been using

confluence.get_page_by_id

and then

page_content =page['body']['storage']['value'], and then inserting the new data and using

confluence.update_existing_page

(pageid, page_title, page_content, type='page', representation='storage', minor_edit=False)

to attempt to update the page, however the page doesn't update but the api call doesn't throw out any messages about failure/ If I update the page_title that gets updated, just not the information in the page macro. Is there a different way I'm meant to go about updating data contained within macros?

Thanks

1 answer

0 votes
Florian Bonniec
Community Champion
October 25, 2022

Hi @Harry 

No I think your way is the way to go. You have to push the entire page content using the API. Note that is you push everytime the same content for test, Confluence will notice that there is no difference and will not update the page/create entry in the page history.

 

Also make sure that you escape all special characters.

I tried it in the past but never success to do the same thing but with JSON content not python. I end up creating a user macro that was decoding base64 and pushed my content encoded in base64 to avoid any issues with special characters.

 

Regards 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events