Forums

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

How to use API token for REST calls in Python?

Yevgen Lasman
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 25, 2018

I'm trying to use a token I've generated per this KB but example is limited to curl and while it works for one and looks like password is just being replaced with the random generated (a token), the same approach (to use a part after : as a password) doesn't work in Python.

If I have a token of john.doe@example.com:asdghlkj3jtklaslkdf, then code below

getCookie = requests.post(url=base + '/rest/auth/1/session', data='{ "username": "' + username + '", "password": "' + password + '" }', headers={'Content-Type': 'application/json'})

returns "Login failed", if I use john.doe@example.com as a user and asdghlkj3jtklaslkdf as a password.

1 answer

1 accepted

3 votes
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2018

Hi @Yevgen Lasman,

The problem is not with Python but with the endpoint called.

Indeed, at this point in time, it is not actually possible to use the API token to create a session using the rest/auth/1/session endpoint. We have the below suggestion open in our system in order to have this possibility added:

JRACLOUD-68026: Make the /rest/auth/1/session endpoint accept API token instead of password

 

Please vote and watch the above feature request in order to be updated on its status. 

 

Cheers,
Dario

Yevgen Lasman
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 27, 2018

Well, I expected this just need a confirmation. Thank you for your help!

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events