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
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.
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