Forums

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

Issue with Authorization on Python

Christian García
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!
October 7, 2021

Good morning community!

I'm working on a project related with confluence for the company I work for and I've been trying to code in Python a simple program to download analytic reports exported to excel, I've been searching through the API and found something that seems to be similar to what I need (here), the issue I am having is that using the code that is provided in the page I referenced before something doesn't seem to work, as everytime I run it I get displayed the following message "{"reason":"InsufficientPermissions"}", and that seems to be that I have not autohrized myself, as in the api token site it's does not update the last access. Does anybody know if I'm not using the code correctly? or can anybody show me an example of how I should be coding the authorization? Because I've been researching through the community posts and I've seen that you can create a Confluence object, but that doesn't seem to be useful for me. Below you have an example of the code I'm using.

import requests
import json

url
= "https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}/label"

headers
= {
"Accept": "application/json",
"Authorization": "Bearer <access_token>"
}

response
= requests.request(
"GET",
url
,
headers
=headers
)

 Thanks in advance.

2 answers

1 accepted

2 votes
Answer accepted
marc -Collabello--Phase Locked-
Community Champion
October 7, 2021

Not sure if that is the cause, but you have to use and access token in a specific format.  See here for how to make this token: https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/#supplying-basic-auth-headers

Christian García
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!
October 7, 2021

It worked, I had to encode the token in base 64 as it said, thanks!!

You'll need to encode your authorization credentials to base64. There are online tools (i.e., https://www.base64encode.net/) that you can use to create your base64 encoded string. For example, your_email@domain.com:your_user_api_token base64 encoded is eW91cl9lbWFpbEBkb21haW4uY29tOnlvdXJfdXNlcl9hcGlfdG9rZW4=

0 votes
Kishan Sharma
Community Champion
October 7, 2021

Hi @Christian García Welcome to the Community! Just change the code below and see if that works -

    "Authorization": "Basic <access_token>"

Suggest an answer

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

Atlassian Community Events