Forums

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

API token access issue

Aditya Rayudu
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!
April 23, 2025

I'm currently working on automating a task that involves updating Jira tickets based on content from a Confluence page. However, I'm running into an issue—I'm unable to access the Confluence page using API tokens. I'm always getting 401 error  Basic Authentication Failure - Reason : AUTHENTICATED_FAILED

Could you please assist me with this, or guide me on how to resolve the API token access issue? 

Thanks in advance for your support!

1 answer

0 votes
Piyush Annadate _ACE Pune_
Community Champion
April 24, 2025

Hello @Aditya Rayudu ,
Welcome to the Community !!

Are you using Scripting language OR performing something in Automation?


Here's 2 cases for your error:
1. Either your account doesn't have the required permission to Create JIRA ticket/Access Confluence page?
2. OR the authentication credentials are not in correct forms.

You can check for below snippets: (Python)

///// For the API TOKEN  and EMAIL ADDRESS
from requests.auth import HTTPBasicAuth
...
auth = HTTPBasicAuth(EMAIL, API_TOKEN)headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

# Make the API request
response = requests.get(url, headers=headers, auth=auth)

 
Perform a base64 encoding: (Snippet taken from ChatGpt)

import requests
import base64

email = "your-email@example.com"
api_token = "your-api-token"
jira_domain = "your-domain.atlassian.net"

# Encode email:token to Base64
auth_str = f"{email}:{api_token}"
b64_auth = base64.b64encode(auth_str.encode()).decode()

headers = {
"Authorization": f"Basic {b64_auth}",
"Accept": "application/json"
}

url = f"https://{jira_domain}/rest/api/3/myself"

response = requests.get(url, headers=headers)



For a check, try to perform a GET query from Postman - just for testing !!

Aditya Rayudu
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!
April 24, 2025

Hi @Piyush Annadate _ACE Pune_ 

Thanks for replying and my and my code is already aligned with the expected format and I'm currently using Scripting Automation, also I have access to both Jira and Confluence

def get_confluence_page():
print("[INFO] Requesting Confluence page...")
auth = HTTPBasicAuth(CONFLUENCE_USERNAME, CONFLUENCE_API_TOKEN)
headers = {
"Accept": "application/json"
"Content-Type": "application/json"
}

response = requests.get(CONFLUENCE_URL, headers=headers, auth=auth)

Piyush Annadate _ACE Pune_
Community Champion
April 24, 2025

I had the same issue, so to turned it as BASIC Auth header.

Example: I'm having JIRA_ADMIN_AUTHSTRING as Basic <Encoded string>

You can create the Basci auth header via  many options, example:
Postman ->  GET query [should be 200 or 201] -> Go to Headers -> Copy the Authorization value as  Basic xxxxxxxx OR  Generate from https://www.debugbear.com/basic-auth-header-generator (won't suggest you to generate from ONLINE, use postman or python script etc/)

def authString = JIRA_ADMIN_AUTHSTRING
// Step 1: Attempt user creation
def userPayload = [
emailAddress: triageDl,
products : []
]
def createUserResponse = post("${baseUrl}/rest/api/3/user")
.header("Authorization", "${authString}")
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.body(userPayload)
.asObject(Map)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events