Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

using the Jira API to list all projects

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

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

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

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!

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,139 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you