If you’ve ever tried to back up your Confluence pages, migrate content to another platform, or automate exports for reporting purposes, you’ve probably noticed the limitations of Confluence’s built-in UI. While Confluence offers manual export options, exporting an entire space can be time-consuming, especially if you have hundreds of pages. Additionally, exporting in bulk to custom formats like Markdown isn’t supported through the standard interface.
Thankfully, the Confluence REST API provides a solution. Using a simple API token and a few lines of Python, you can programmatically fetch pages, attachments, and even convert them into formats that fit your workflow. In this guide, we’ll walk through every step of exporting your Confluence content efficiently and safely.
Step 1: Get Your API Token
For Confluence Cloud users, Atlassian requires an API token instead of your account password. This ensures secure authentication when accessing the REST API.

Here’s how to generate your API token:
- Go to your Atlassian account settings.
- Navigate to Create API token.
- Give your token a descriptive name, such as
Confluence Export. - Copy the token and store it securely.
When authenticating with the API:
- Email address: Your Atlassian login
- API token: Use this instead of your password
For Confluence Server or Data Center, you can authenticate using your username and password or a personal access token. Regardless of the version, API tokens make automation safer and more manageable.
Step 2: Understand the Key REST API Endpoints
Before writing any code, it’s important to understand which REST API endpoints you’ll need for exporting content. Here are the most commonly used endpoints for content export:
- Get Page Content
GET /wiki/rest/api/content/{pageId}?expand=body.viewThis returns the HTML content of a page. Replacebody.viewwithbody.storageif you want Confluence’s raw XML-like storage format. - Get All Pages in a Space
GET /wiki/rest/api/space/{spaceKey}/content?limit=100This retrieves all pages within a space. The results are paginated, so you may need to handle multiple pages for large spaces. - Get Attachments
GET /wiki/rest/api/content/{pageId}/child/attachmentThis endpoint fetches all attachments linked to a particular page, including images, PDFs, and other files.
Understanding these endpoints helps you design a workflow that efficiently extracts all the content you need.
Step 3: Export Content Using Python
Python is an ideal language for automating Confluence exports because of its simplicity and the availability of libraries like requests for HTTP calls. Below is a sample script that exports all pages and attachments from a Confluence space:
import requests
import os
# === CONFIG ===
BASE_URL = "https://your-domain.atlassian.net/wiki"
EMAIL = "your-email@example.com"
API_TOKEN = "your-api-token"
SPACE_KEY = "TEST"
EXPORT_DIR = "confluence_export"
# === SETUP ===
auth = (EMAIL, API_TOKEN)
os.makedirs(EXPORT_DIR, exist_ok=True)
# Get all pages in the space
def get_space_pages():
url = f"{BASE_URL}/rest/api/space/{SPACE_KEY}/content?limit=100"
response = requests.get(url, auth=auth)
response.raise_for_status()
return response.json()["page"]["results"]
# Save page as HTML
def get_page_content(page_id, title):
url = f"{BASE_URL}/rest/api/content/{page_id}?expand=body.view"
response = requests.get(url, auth=auth)
response.raise_for_status()
html_content = response.json()["body"]["view"]["value"]
filename = os.path.join(EXPORT_DIR, f"{title}.html")
with open(filename, "w", encoding="utf-8") as f:
f.write(html_content)
print(f"✅ Saved page: {filename}")
# Download attachments
def download_attachments(page_id):
url = f"{BASE_URL}/rest/api/content/{page_id}/child/attachment"
response = requests.get(url, auth=auth)
response.raise_for_status()
attachments = response.json().get("results", [])
for att in attachments:
download_link = att["_links"]["download"]
filename = att["title"].replace("/", "_")
file_url = f"{BASE_URL}{download_link}"
resp = requests.get(file_url, auth=auth)
with open(os.path.join(EXPORT_DIR, filename), "wb") as f:
f.write(resp.content)
print(f"📎 Downloaded attachment: {filename}")
if __name__ == "__main__":
pages = get_space_pages()
for page in pages:
page_id = page["id"]
title = page["title"].replace("/", "_")
get_page_content(page_id, title)
download_attachments(page_id)
This script:
- Exports each page as an
.htmlfile - Downloads all attachments to the same folder
- Handles multiple pages in a space efficiently
Step 4: Run the Script
- Save the script as
export_confluence.py - Install dependencies:
pip install requests - Run the script:
python export_confluence.py
After running, you’ll have a local folder containing all pages and attachments from the selected Confluence space, ready for migration, backup, or conversion.
Why Using the REST API for Exports Is Better
Automating exports with the Confluence REST API has several advantages:
- Automated: No more manual clicks through the UI
- Flexible: Convert HTML files to Markdown or PDF using tools like Pandoc
- Granular: Export only the pages or attachments you need
- Reusable: Integrate the script into migration pipelines or scheduled backups
This approach is especially useful for teams managing large spaces or needing frequent backups.
Next Steps
Once you’ve exported your content, you can extend your workflow:
- Convert HTML to Markdown for GitHub or GitLab wikis
- Set up a cron job to schedule automated backups
- Handle pagination to export spaces with thousands of pages
- Enhance logging to track exported pages and attachments
By leveraging the REST API and Python, you gain full control over your Confluence content, reduce manual effort, and ensure your data is safe and accessible.






