Forums

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

Update table in Confluence through Python (atlassian package) and attach some files

Anastasia
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!
February 14, 2023

I created a Confluence page some time ago, where there is one table. Periodically I need to add additional row and to put some text there. I would like to automate it. Besides, in the last column I need to upload some files.

I wrote a code that can get (download) table from Confluence page. But I am thinking, how to write new information in new row in that table in Confluence through Python. From research that I have carried out I decided that I need to update that table in Python (as dataframe) that I have got from Confluence. After that upload new table into Confluence. Is this idea correct?

I suppose that modified table (dataframe) in Python I need to put as

conf.update_page(page_id, page_content), 

However, I get an error like "Object of type DataFrame is not JSON serializable". Could you help me, please? I do not know, how to solve it. Perhaps, something is incorrect.

As I have written before, I need to attach some documents to the last column of the table. I completely do not understand how to do it. There are some functions that can attach something to Confluence, but I need to attach files in the last column and the last (created) row. Do I need to do it in dataframe (modified table) in Python or should I do it in Confluence after uploading modified table there? If so, I do not understand, how to explain to Python to put it exactly in the last column as I only download table to Python from Confluence. Moreover, when

Below there is a code, by which I got table from Confluence.

     from atlassian import Confluence
     import pandas as pd

     conf_site = 'https://confluence.company.com/'
     conf_user = "login"
     conf_pass = "password"
     page_id = 0000000000

     conf = Confluence(url=conf_site, username=conf_user, password=conf_pass)
     page = conf.get_page_by_id(page_id, expand='body.view')
     page_content = page['body']['view']['value']

     table = pd.read_html(page_content)
     table = table[0]

This table was open in Python as dataframe and I created new row in it and put essential information. However, I do not comprehend, how to add it to Confluence page. I got an error written above.

 

Thank you in advance!

1 answer

0 votes
Sunny Ape
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.
February 16, 2023

Hello @Anastasia 

"After that, upload new table into Confluence. Is this idea correct?". In short, no.

You can't selectively 'upload' or edit random parts or sections of a content page, like a table.

You need to download the entire content page, make the required changes using your Python code, then upload the entire new content back into the page, effectively over-writing all the content... which in turn makes your new content the new version of that page.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events