import os from atlassian import Confluence CONFLUENCE = Confluence( url=f"https://{os.environ['CONFLUENCE_SITE']}.atlassian.net", username=os.environ['CONFLUENCE_USER'], password=os.environ['CONFLUENCE_TOKEN'], cloud=True) def get_confluence_page_source(title: str = None, page_id: int = None): """ Retrieve a string representing the body of a Confluence page as Confluence Storage Format. see: https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html Useful to get macros and other formatting not found in the normal body contents. Parameters: title : (optional if page_id is given) the name of the page to retrieve (must have environment variable "CONFLUENCE_SPACE" set) page_id : (optional if title is given) the page ID to retrieve, eg. 28280848470 Examples: >>> CONFLUENCE = Confluence( url=f"https://{os.environ['CONFLUENCE_SITE']}.atlassian.net", username=os.environ['CONFLUENCE_USER'], password=os.environ['CONFLUENCE_TOKEN'], cloud=True) >>> get_confluence_page_source(page_id=os.environ['CONFLUENCE_PARENT_PAGE_ID']) '10container_overview.jsonname

' """ args = {'expand': 'body.storage'} if title is None and page_id is None: raise ValueError('must specify either title or page_id') elif title is not None: r = CONFLUENCE.get_page_by_title(title=title, space=CONFLUENCE_SPACE, expand='body.storage') elif page_id is not None: r = CONFLUENCE.get_page_by_id(id=page_id, expand='body.storage') return r['body']['storage']['value']