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!
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 !!
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/)
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.