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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

trying to update a confulence table using python script

shahbaaz.imamkhan
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!
Nov 15, 2023
from bs4 import BeautifulSoup
from atlassian import Confluence

confluence = Confluence(
token="my_token",
cloud=True,
)

page_id = 00000000
page = confluence.get_page_by_id(page_id, expand="body.view,version.number")
page_content = page['body']['storage']['value']
version = page['version']['number'] + 1

soup = BeautifulSoup(page_content, 'html.parser')
table = soup.find('table', {'class': 'relative-table wrapped tf-macro'})

headers = [header.text.strip() for header in table.find_all('th')]

table_data = {header: [] for header in headers}
for row in table.find_all('tr')[1:]:
    data = [td.text.strip() for td in row.find_all('td')]

    for header, value in zip(headers, data):
          table_data[header].append(value)

new_value = {
'Change Created': 'NEW_CHANGE',
'Stage': 'PROD/LIVE',
'Valid until': 'NEW_DATE',
'Status': 'NEW_STATUS',
'Notes': 'NEW_NOTES'
}

for header, value in new_value.items():
      table_data[header].insert(0, value)

updated_table_html = "<table>"
updated_table_html += "<tr>" + "".join([f"<th>{header}</th>" for header in table_data.keys()]) + "</tr>"
for row in zip(*table_data.values()):
    updated_table_html += "<tr>" + "".join([f"<td>{data}</td>" for data in row]) + "</tr>"
updated_table_html += "</table>"

updated_content = f"{soup}\n{updated_table_html}"


# Update page
confluence.update_page(
page_id=0000000,
title='Certificate',
body= {
"storage": {
"value": updated_content
}
},
representation= 'storage',
always_update=True,
type='page',
minor_edit=False,
)
----------------------------------------
I get this error
version = self.history(page_id)["lastUpdated"]["number"] + 1
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'lastUpdated'
Not able to understand what is the error here.
This is my first time using the Confluence API, any help in good direction would be really helpful

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events