So normally when i go into browser and hit export to docx , its working perfectly fine , im able to download the doc , but programatically i tried doing that with the api and every time i get a sinle page as output ( that is the login page ) . Here is the code i used .
import requests
CONFLUENCE_BASE_URL = "https://your-domain.atlassian.net/wiki" # Change this
PAGE_ID = "123456" # Change to your page's ID
PAT = "your_confluence_pat" # Your Personal Access Token
url = f"{CONFLUENCE_BASE_URL}/exportword?pageId={PAGE_ID}"
headers = {
"Authorization": f"Bearer {PAT}",
"Accept": "application/msword"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
with open("confluence_export.doc", "wb") as f:
f.write(response.content)
print("Exported successfully!")
else:
print(f"Failed! Status: {response.status_code}")
print(response.text)
Thanks in advance
Hi @Manoj ,
OPTION1: Use the REST API to fetch page content and generate word manually
confluence Cloud REST API lets you fetch page content via:
GET /wiki/rest/Api/content/{id}?expand=body.storage
Then, you can:
while this isn’t as clean as native export, its programmatic and wors well.
OPTION2: Use browser automation
if you must replicate the browser (e.g., Selenium with ChromeDriver)
Log in using a real user session
Navigate to the export URL and trigger the download
this method mimics the browser and bypasses the logic page issue your hitting.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.