atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 642 forks source link

[Confluence] Using create_page method with None as body causes 500 Internal Server Error #1345

Open pauldevlin-smarsh opened 3 months ago

pauldevlin-smarsh commented 3 months ago

When using the Confluence API (version 3.5.2), a 500 internal error when trying to send a create_page request to Confluence. A similar issue occurs when using an updated version (3.41.11) which rases the following error: raise HTTPError(error_msg, response=response) requests.exceptions.HTTPError: com.atlassian.confluence.api.service.exceptions.ServiceException: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "unclean" is null

The following script reproduces the error.

from atlassian import Confluence

confluence = Confluence(
    url=<ATLASSIAN_URL>,
    username=<ATLASSIAN_USER>,
    password=<ATLASSIAN_KEY>
)

def createPageIfNotExists(space,parentId,title):
    print(f'Checking if {space}\\{parentId}\\{title} exists.')
    pageExists = confluence.page_exists(space, title)
    if not pageExists:
        print(f'{space}\{parentId}\{title} does not exist.It will be created.')
        print(f"Creating page with space: {space}, title: {title}, parentId: {parentId}")
        confluence.create_page(space, title, None, parent_id=parentId, type='page', representation='storage', editor='v2')
    pageId = confluence.get_page_id(space, title)
    return pageId

createPageIfNotExists("Test", "123456", "TestPage")

Updating the following line to send "" as the body resolves the issue in both versions: confluence.create_page(space, title, "", parent_id=parentId, type='page', representation='storage', editor='v2')

The following code could be updated in confluence.py to default the body to "": def create_page( self, space, title, body="", parent_id=None, type="page", representation="storage", editor=None, full_width=False, ):

This would resolve the issue and since the Atlassian API requires it it will cover scenarios with or without and body of string being sent