I'm trying to get table contents from a Confluence page in JSON format. It's all SSO so I can only use an API key and I haven't found a way to access Confluence with the requests library. Unfortunately, the output of the Confluence API is plain html.
This is what I've got so far. Can the Confluence library output tables in JSON format (rather than displaying the raw html code in a dictionary)?
from atlassian import Confluence
import os
user = "me@myself.com"
api_key = os.environ['confluence_api_key']
server = "https://xxxxxx.atlassian.net"
api_url = "/rest/api/content"
page_id = "12345"
confluence = Confluence(url=server, username=user, password=api_key)
page = confluence.get_page_by_title("TEST", "page 1", expand="body.storage")
content = page["body"]["storage"]
print(content)
And the output looks like this:
{'value': '<p>Something something.</p><p /><table data-layout="default" ac:local-id="xxx"><colgroup><col style="width: 226.67px;" /><col style="width: 226.67px;" /><col style="width: 226.67px;" /></colgroup><tbody><tr><th><p><strong>name</strong></p></th><th><p><strong>type</strong></p></th><th><p><strong>comment</strong></p></th></tr><tr><td><p>text1</p></td><td><p>varchar(10)</p></td><td><p /></td></tr><tr><td><p>123</p></td><td><p>int</p></td><td><p /></td></tr></tbody></table>', 'representation': 'storage', 'embeddedContent': [], '_expandable': {'content': '/rest/api/content/12345'}}
404 error with the requests library:
request_url = "{server}{api_url}/{page_id}?expand=body.storage".format(
server=server, api_url=api_url, page_id=page_id
)
requestResponse = requests.get(request_url, auth=(user, api_key))
print(requestResponse.status_code)