I have a small problem with getting all projects from JIRA with Python.
I'm using this code with my access token:
import requests import json url = "https://mydomain.atlassian.net/rest/api/3/project/" headers = { "Accept": "application/json", "Bearer": "Access_token" } response = requests.request( "GET", url, headers=headers ) print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
This returns 200, but with an empty array. I've also tried getting a single project with
/rest/api/3/project/{projectkey}
but this gives an error that this projectid is not found or I don't have the access rights (which I do have).
Any thoughts on what might be the problem here? What should I add or change or try to get this working?
Thanks!
Hi @miik aal ,
Your script is trying to authenticate the REST API calls using Bearer authentication, but it looks like you wanted to use Basic Authentication with API Token instead.
For details on the supported ways (and examples) to authenticate REST API calls please see:
Also, by searching the community you can find some examples on how to authenticate REST API calls in Python like in the following thread:
I hope this helps.
Cheers,
Dario
Hi Dario,
Thanks for your reply! (Thanks to @Oliver Siebenmarck _Polymetis Apps_ also)
That was exactly the problem. Used basic auth and now it worked. :)
Br,
Miikka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @miik aal ,
You are not alone and I have seen a lot of customers confused by the examples provided in the REST API documentation page. Therefore I have opened below request to have the documentation fixed:
For the rest, I am happy to know that everything is now working! :)
Have a nice day,
Dario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Miik,
I'd venture a guess that your authentication token does not work as expected and that you are not really logged in. The resource
/rest/api/3/project/
is accessible anonymously, so if you're not logged in an http 200 with an empty list would be the expected result. (It's also deprecated so, you might want to look at the alternative /rest/api/3/project/search).
I hardly ever Python and basic auth with Jira anymore, but if I remember correctly, the API expects your token in a different format. You can check the documentation here (sadly, without a Python example).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.