Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active July 28, 2023 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandesant/1cfe53b6f7a398d9fff970d9c87ec967 to your computer and use it in GitHub Desktop.
Save juandesant/1cfe53b6f7a398d9fff970d9c87ec967 to your computer and use it in GitHub Desktop.
Confluence API examples
from atlassian import Confluence # requires atlassian-python-api
cf_user = os.environ['CONFLUENCE_USER'] # requires environment variable
cf_pwd = os.environ['CONFLUENCE_PWD']
cf_url = os.environ['CONFLUENCE_URL']
cf_space = os.environ['CONFLUENCE_SPACE']
# Content preparation
my_title = "Testing Confluence API"
html_body = """<p>Paragraph 1</p>
<p>Paragraph 2</p>
"""
# Get a Confluence instance
confluence = Confluence(url=cf_url, username=cf_user, password=cf_pwd)
# Use the Confluence instance to create a page
cf_result = confluence.create_page(cf_space, my_title, html_body, parent_id=None, type='page', representation='storage')
# Get the created page id from the results
page_id = cf_result['id']
# Create new content
my_title = "Testing Confluence API — New title"
html_body = "<p>This is new content replacing the previous one.</p><p>You can see the previous content in the history.</p>"
cf_result = confluence.update_page(page_id, my_title, html_body)
@juandesant
Copy link
Author

Alternatively, you can use a personal authorization token. See these gists for the alternative approach:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment