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

How to get Admins of a particular project in Bitbucket using rest api

Hi,

I tried to use following API ******/REST/API/1.0/PROJECTS/ACSC/PERMISSIONS/USERS?FILTER=PROJECT_ADMIN

with headers

Content-type:applicaiton/json

Accept:Application/json

 

But I am getting list of admins of that project. I do understand that FILTER value could be different but in rest api doc, there is no request example.

https://docs.atlassian.com/bitbucket-server/rest/5.1.0/bitbucket-rest.html#idm45588158637696

 

Thanks,

Mansi

1 answer

1 accepted

1 vote
Answer accepted

Hi @Mansi Patel,

 

The filter is not based on the role of the user, instead it is based on the username.

 

Let's work through an example here.

 

Let's say that we have 3 users and a project called project1:

- charlie (with Admin permissions on project1)

- user1 (with Admin permissions on project1)

- user2 (with Write - but not Admin - permissions on project1)

 

I then use the rest endpoint to retrieve the details of the users.

 

Example one - no filter applied

/rest/api/1.0/projects/project1/permissions/users

This will be the response:

{"size":3,"limit":25,"isLastPage":true,"values":[
{"user":{"name":"charlie",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user1",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user2",...,"permission":"PROJECT_WRITE"}],...

 

Example two - filtering for user as username

/rest/api/1.0/projects/project1/permissions/users?filter=user

This will be the response:

{"size":2,"limit":25,"isLastPage":true,"values":[
{"user":{"name":"user1",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user2",...,"permission":"PROJECT_WRITE"}],...

The charlie user is not listed because it does not match contain the "user" string.

Example three - filtering for r as username

/rest/api/1.0/projects/project1/permissions/users?filter=r

This will be the response:

{"size":3,"limit":25,"isLastPage":true,"values":[
{"user":{"name":"charlie",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user1",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user2",...,"permission":"PROJECT_WRITE"}],...

All users are returned because they all contain "r" in their username.

 

Note: the response in the examples is truncated and the less relevant details have been replaces with "..."

 

 

Does this help? If you could share what you are trying to achieve, we may be able to provide a more specific reply.

 

Cheers,

Caterina - Atlassian

Hi Caterina,

 

Thanks for details response, I can work with following Api.

/rest/api/1.0/projects/project1/permissions/users

This will be the response:

{"size":3,"limit":25,"isLastPage":true,"values":[
{"user":{"name":"charlie",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user1",...,"permission":"PROJECT_ADMIN"},
{"user":{"name":"user2",...,"permission":"PROJECT_WRITE"}],...

 Also, as I understand there is no specifically API to filter based on project permissions. In my opinion, it makes senses to have API to filter based on Permissions so that we don't need to filter through response.

 

Thanks,

Mansi

Hi @Mansi Patel,

Great! It is correct that there is no specific API to filter on project permissions.

Have a look at this article as well (if you did not already):

How to report on permissions by querying the database

 

Cheers,

Caterina - Atlassian

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Atlassian supported Jenkins integration for Bitbucket Server

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...

398 views 0 9
Read article

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