Confluence

Due to Marketplace Limitations, this integration can’t run seamless direct via app connection, so this class is made necessary for Confluence Integration.

The Confluence class facilitates interaction with Confluence's REST API.

It provides methods for performing HTTP GET, POST, and PUT requests to various API endpoints, enabling actions such as retrieving pages, spaces, creating pages, and updating page content.

Additionally, it includes a nested Page class for handling page-specific operations such as retrieving page content, replacing text within the content, and bulk replacing text based on a mapping. The class also allows authentication using email and token, and provides properties for authentication details and request headers.

# Instantiate Confluence object confluence = Confluence(instance_url='https://your-confluence-instance-url.com', email='your-email@example.com', token='your-api-token') # Retrieve a list of spaces spaces = confluence.spaces logger.info("Available Spaces:") for space in spaces: logger.info(f"{space['key']} - {space['name']}") # Create a new page in a space space_key = 'SPACEKEY' new_page_title = 'New Page Title' new_page_content = 'Content of the new page' new_page = confluence.create_page(spacekeyorid=space_key, title=new_page_title, content=new_page_content) logger.info("New Page Created Successfully.") # Retrieve a specific page by its page ID page_id = 'page_id_here' page = confluence.get_page(pid=page_id) # Get the content of the page in storage format page_content = page.storage logger.info("Page Content:\n%s", page_content) # Replace text within the page content new_page_content = page.replace(actual_val='old_text', new_val='new_text') logger.info("Page Content After Replacement:\n%s", new_page_content) # Bulk replace text within the page content based on a mapping text_mapping = {'old_text1': 'new_text1', 'old_text2': 'new_text2'} bulk_replaced_content = page.bulk_replace(mapping=text_mapping) logger.info("Page Content After Bulk Replacement:\n%s", bulk_replaced_content)

Easy for Jira - Python Automations, 2023