Retrieve list of projects for particular user with BROWSE permission (API/SQL)

Bartosz Kaczyński January 22, 2020

I can't find proper methods even combining more than one in https://docs.atlassian.com/software/jira/docs/api/REST/latest/

Or maybe there is an equivalent SQL query to get this information.

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 23, 2020

Hi,

If I understand your request, you are using Jira Server and you want to be able to see all the projects that a user has the browse permission on.  In this case, this is something you can lookup via the REST API. Specifically you can use the endpoint GET /rest/api/2/project.  This endpoint is permissions based, so it only returns projects that the user making the REST API call has access to:

Returns all projects which are visible for the currently logged in user. If no user is logged in, it returns the list of projects that are visible when using anonymous access.

It might also be possible to find this information via SQL, but I would imagine the query might be somewhat complicated to write up given the different ways permissions can be assigned in Jira (to user, to a group, or to a project role).

I hope this helps.

Andy

Bartosz Kaczyński January 24, 2020

It would be great if I could add a username parameter to this method (e.g. GET /rest/api/2/project?username=administrator) because I need to filter this information to build an external tool. But this is not available. Any alternatives?

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 27, 2020

Ah, I see what you are getting at now.  However there is not a single REST API endpoint in Jira Server today that can return this information.  You could potentially use the endpoint GET /rest/api/2/user/viewissue/search. This endpoint can search for a supplied username's browse permissions, but you have to supply it with either an issuekey or a project key when doing so.

So perhaps if you can get together a list of all the project keys, perhaps by doing a GET /rest/api/2/project first, and then say build some kind of script (i think perl or python could do this, but I'm not well versed in the exact syntax here) to make calls to the GET /rest/api/2/user/viewissue/search endpoint with the same username, and changing the project key for each call to see if it can build you a complete list.  

It would return a lot of json if you have a lot of projects, but it seems like this could get you back the results I think you want to see here.

Like Bartosz Kaczyński likes this

Suggest an answer

Log in or Sign up to answer