I'm trying to access the confluence REST API from Python for creating and updating pages. I followed the following instructions to generate an API key since basic auth for passwords was deprecated:
I've since tried accessing the Confluence API with my key using several methods:
- Postman
- curl
- Python requests library
- Python confluence module
All of the options return (or similar error if using the Atlassian Python module)
401: Basic authentication with passwords is deprecated. For more information, see: https://developer.atlassian.com/cloud/confluence/deprecation-notice-basic-auth/
For reference here are the Python and curl scripts. Below the username is my email and the api token was obtained through the confluence dashboards as outlined above. I've tried two different API tokens and both behave the same.
My company authenticates through Okta, is there some additional step I need to take to enable programmatic access?
Requests Code:
import requests
from requests.auth import HTTPBasicAuth
username: str = 'my_email'
token: str = 'my_api_key'
url: str = 'https://<my_company_domain>.atlassian.net/status'
auth = HTTPBasicAuth(username,token)
r = requests.get(url=url,auth=auth)
print(f'{r.status_code}: {r.content}')
This returns
401: Basic authentication with passwords is deprecated. For more information, see: https://developer.atlassian.com/cloud/confluence/deprecation-notice-basic-auth/
Confluence Module Code
from atlassian import Confluence
username: str = 'my_email'
token: str = 'my_api_key'
url: str = 'https://<my_company_domain>.atlassian.net/wiki'
confluence = Confluence(
url = url,
username = username,
token = token,
cloud=True
)
confluence.get_user_details_by_username(username)
This returns
HTTPError: Request rejected because issuer is either not authorized or not authorized to impersonate
cURL:
curl -v https://<my_company_domain>.atlassian.net/status --user <username>:<api_token>
This returns
Basic authentication with passwords is deprecated. For more information, see: https://developer.atlassian.com/cloud/confluence/deprecation-notice-basic-auth/