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

Mansi Patel Apr 19, 2018

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
Caterina Curti Atlassian Team Apr 26, 2018 • edited Apr 27, 2018

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

Mansi Patel Apr 27, 2018

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

Caterina Curti Atlassian Team Apr 27, 2018

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,995 views 1 19
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