Forums

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

JIRA REST API cannot find projects (returns 200)

miik aal
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!
July 1, 2019

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!

 

2 answers

1 accepted

0 votes
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 3, 2019

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

miik aal
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!
July 4, 2019

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

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 4, 2019

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

1 vote
Oliver Siebenmarck _Polymetis Apps_
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.
July 1, 2019

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).

Suggest an answer

Log in or Sign up to answer