Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

API Token not working with REST calls (basic auth deprecated)

paul.bruillard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 9, 2023

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/

 

2 answers

0 votes
Oliver Siebenmarck _Polymetis Apps_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2023

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

0 votes
Mohamed Benziane
Community Champion
February 13, 2023

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})
paul.bruillard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 17, 2023

The server response is just a redirect to the login page.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events