using the Jira API to list all projects

benji78 December 21, 2020

I am having a little trouble with something that I think should be quite simple. I've created an OAuth2 (3LO) app for Jira (on Atlassian Cloud) and have successfully connected to it with my app (i.e.: got the token and I can call the API).

I call the API to get the correct "cloudId" as the documentation states.

The user that I am authenticating with when connecting via OAuth2 is an Administrator for the Jira project that I am trying to query.

When I use this endpoint:

> https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-projects/#api-rest-api-3-project-search-get

I get a response, but an empty one (i.e.: no projects listed):

> {"jira":{"self":"https://api.atlassian.com/ex/jira/[my-cloud-id]/rest/api/3/project/search?maxResults=50&startAt=0","maxResults":50,"startAt":0,"total":0,"isLast":true,"values":[]}}

The documentation states, as I understand it, that I should get a list of any project that the logged in user has "browse" or "administration" permissions for. My user has both.

Has anyone had a similar trouble?

Thanks in advance,
Ben


----------


Edit: searching by a specific project key works.

> https://api.atlassian.com/ex/jira/[my-cloud-id]/rest/api/3/project/TESTJ

So I therefore no longer think that this is a permissions issue.

The URL:

> https://api.atlassian.com/ex/jira/[my-cloud-id]/rest/api/3/project/search

Still returns an empty list of projects. I wonder if I am missing some kind of important parameter on this call?

2 answers

1 vote
benji78 December 22, 2020

Oops! This is my fault. Thank you @Bill Sheboy for the answer and indeed you are correct that the endpoint works.

I simply had the required HTTP header set to:

 

> token <token>

 

Instead of:

 

> Bearer <token>

 

So muppetry on my part, but perhaps this will help someone else one day!

Bill Sheboy
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.
December 22, 2020

Hi @benji78 

I am glad that worked for you.  To help others find the solution faster, please consider marking this question as answered.  Thanks!

__Bill

0 votes
Bill Sheboy
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.
December 21, 2020

Hi @benji78  -- Welcome to the Atlassian Community!

I just tried getAllProjects and it worked for me:

https://docs.atlassian.com/software/jira/docs/api/REST/1000.824.0/#api/2/project-getAllProjects

Best regards,

Bill

benji78 December 22, 2020

Hi @Bill Sheboy thanks for your reply.

I had not seen this documentation before, so thank you for the reference. However, is seems that this API is authenticated via OAuth 1.0a or HTTP Basic Auth? I am attempting to support OAuth 2.0.

When I call the endpoint that you cite I get all public repositories, rather then private ones that I have access to. This implies to me that the API is not using my access token to authenticate.

I also note that the API root is different. In the API that you reference it is `https://jira.atlassian.com` but in the OAuth2 API it is `https://api.atlassian.com` with the latter requiring the "cloud ID" to be present in the URL.

Using the OAuth2 API here are my results:

 

`https://api.atlassian.com/ex/jira/${jiraUser.extra.cloudId}/rest/api/2/project/TESTJ`

{"jira":{"expand":"description,lead,issueTypes,url,projectKeys,permissions,insight","self":"https://api.atlassian.com/ex/jira/ceef92b6-5ab7-4202-861d-ca1b2c54346d/rest/api/2/project/10000","id":"10000","key":"TESTJ"

 

`https://api.atlassian.com/ex/jira/${jiraUser.extra.cloudId}/rest/api/2/project`

{"jira":[]}

 

And the same responses from the version 3 URLs.

It seems suspicious to me that specifying `TESTJ` at the end of the URL renders a result, but leaving this out does not return all projects...

 

Cheers,

Ben

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events