The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello Everyone,
I created an access token in the atlassian web application and it works when I use curl like this:
curl --user "petar.dimovski@etxcapital.com:TOKEN https://etxcapital.atlassian.net/wiki/rest/api/content&type=page
but when I ping the api from a python script I get the following response:
{"message":"Current user not permitted to use Confluence","statusCode":403}
What should I do in order to make it work like curl does?
Here's the python script:
import os
import requests
from requests.auth import HTTPBasicAuth
confluence_api_url ="https://etxcapital.atlassian.net/wiki/rest/api"
def get_auth_details():
return HTTPBasicAuth(os.getenv("username"), os.getenv('token'))
def get_pages(label=None):
params = {
'type':'page',
# 'start':0,
# 'limit':500
}
if label:
params["label"] = label
resp = requests.get(f"{confluence_api_url}/content/search.json",
auth=get_auth_details(),
params=params)
return resp.json()
Hi @Petar Dimovski Welcome to the Atlassian Community!
You'll need to encode your authorization credentials to base64 which is important step, you can refer it here on how to do it. Also take a look at sample script on this link
Let me know if that help!
Hi @Kishan Sharma , Thank you for taking your time to help me.
After encoding my credentials I get the following error as a response:
Basic authentication with passwords is deprecated. For more information, see: https://confluence.atlassian.com/cloud/deprecation-of-basic-authentication-with-passwords-for-jira-and-confluence-apis-972355348.html
My username is the email and token is the API Token.
Here is the relevant part of the code:
def get_auth_details():
print(os.getenv('username'))
s=f'{os.getenv("username")}:{os.getenv("token")}'
encoded=base64.b64encode(s.encode())
print(s)
print(f"Encoded:{encoded}")
print(f"Decoded:{base64.b64decode(encoded)}")
return f"Basic {encoded}"
def get_pages(label=None):
params = {
'cql':'type=page',
}
if label:
params["cql"] += f" and label={label}"
resp = requests.get(f"{confluence_api_url}/content/search.json",
headers={'Authorization':get_auth_details(),'Content-Type': 'application/json'},
params=params)
return resp.json()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to Supply an Authorization header with content Basic followed by the encoded string.
Example:
Authorization: Basic eW91cl9lbWFpbEBkb21haW4uY29tOnlvdXJfdXNlcl9hcGlfdG9rZW4=
ie - "Authorization: Basic <your_encoded_string>"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you can see in the code, in the headers parameter I have a dictionary which gives the Authorization header of Basic "encoded string" (that is what get auth details returns).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah ok, I am not so very good at python. If you try this using postman is that working ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please post your answer here if you have got it working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Community! Thank you to all who joined our ongoing monthly Atlassian Access demo! We have an engaging group of attendees who asked many great questions. I’ll share a recap of frequently ask...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.