pythonpython-3.xconfluencecommit-messageatlassian-python-api

Setting a commit message / update comment when editing a page with Atlassian Confluence Python API


I am using the atlassian-python-api to update a page as described in the documentation:

from atlassian import Confluence

conf = Confluence(url=srvr, username=usr, password=pswd)

page_id = '12345'

new_page_title = 'This is a new title'
new_page_body = '<p>This is a new body</p>'

conf.update_page(page_id, new_page_title, new_page_body)

This works fine. I now want to add an update comment / commit message like one can enter when editing a page manually ("What did you change?").

The atlassian-python-api documentation of update_page() has no such option. Is it possible?

I tried to change the page body to include this

data = {
    'id': {page_id}
    'title': new_page_title,
    'body': {
        'storage':{
            'value': new_page_body,
            'representation':'storage',
        }
    },
    'version': {
        'number': 2
    },
    'comment': 'Changed the title and the body.'
}

but I guess this is not how update_page() works, I get an

AttributeError: 'dict' object has no attribute 'strip'


Solution

  • This is actually directly possible with update_page(), though you are correct, it is not documented in the method's documentation.

    I found in the source code that the method update_page() takes an optional argument version_comment. This is the comment that you want to set.

    Extending your example:

    from atlassian import Confluence
    
    conf = Confluence(url=srvr, username=usr, password=pswd)
    
    page_id = '12345'
    
    new_page_title = 'This is a new title'
    new_page_body = '<p>This is a new body</p>'
    commit_msg = 'Changed the title and the body.'
    
    conf.update_page(page_id, new_page_title, new_page_body, version_comment=commit_msg)
    

    This should do what you want.