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:
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/
Hi @paul.bruillard ,
From what I can tell by looking at your examples, you are not doing anything wrong or differently then I typically do.
Which leads me to believe, that maybe it has something to do with the central authentication. There might a global setting or policy that forbids API access, while I have not seen or used anything like this so far, I've heard about a few times. Might definitely be worth to reach out to your org admin and see if they have anything set up.
Hope that helps,
Oliver
Hi,
Welcome to the community
With python if you want to use the API token you can try this :
import requests
token = "API Token"
response = requests.get("https://<yourUrl>/rest/api/2/",headers={'Authorization': "Bearer " + token})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The server response is just a redirect to the login page.
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.