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