Last active
July 28, 2023 14:48
-
-
Save juandesant/1cfe53b6f7a398d9fff970d9c87ec967 to your computer and use it in GitHub Desktop.
Confluence API examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, you can use a personal authorization token. See these gists for the alternative approach: