Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how to add existing user group to repository on bitbucket with REST API

ext.momcilo.vasic
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 20, 2022

Hi I'm trying to create a script which will add existing user group to repository on bitbucket.

I tried something like this: 

 

groups_for_adding = f'https://api.bitbucket.org/1.0/group-privileges/{workspace}/{repo}/{groupname} --data write'
response = requests.put(groups_for_adding, auth=HTTPBasicAuth(username, password))
print(response)

 

Also tried solutions from this link:

https://support.atlassian.com/bitbucket-cloud/docs/invitations-endpoint/

 

Any help is very welcomed... :)

 

1 answer

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 20, 2022

Hi @ext.momcilo.vasic

Welcome to the community.

I've checked our API v1 documentation and compared it with the endpoint you've used and I believe you're just missing the "group_owner" which is the same as the workspace ID.

You can check the documentation on this link (Under "PUT group privileges on a repository").

Here's the exact endpoint:

PUT https://api.bitbucket.org/1.0/group-privileges/{workspace_id}/{repo_slug}/{group_owner}/{group_slug} --data "{privilege}"

As an example, if your repository is: some_workspace/some_repo
And your user group name is: some_group

The API endpoint would be:

https://api.bitbucket.org/1.0/group-privileges/some_workspace/some_repo/some_workspace/some_group

Btw, please also make sure you're using an App password (as your password credential) as we recently deprecated the Atlassian account password.

Hope it helps and do let me know if you have further questions that I can help with.

Regards,
Mark C

ext.momcilo.vasic
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 21, 2022

thanks for the answer, with this api I'm getting following answer

curl --request PUT --user user:password PUT https://api.bitbucket.org/1.0/group-privileges/{workspace_id}/{repo_slug}/{group_owner}/{group_slug} --data "{privilege}"

is not a valid privilege

tried with this commands:

curl --request PUT --user user:password https://api.bitbucket.org/1.0/group-privileges/some_workspace/some_repo/some_workspace/some_group --data read

curl --request PUT --user user:password https://api.bitbucket.org/1.0/group-privileges/some_workspace/some_repo/some_workspace/some_group --data "read"

 

any idea what is wrong?

Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2022

Hi @ext.momcilo.vasic

I've tried the similar CURL Command below, however, it works fine on my end using an App password.

curl --request PUT --user user:password https://api.bitbucket.org/1.0/group-privileges/some_workspace/some_repo/some_workspace/some_group --data read

Would you be able to confirm if you're using an App password?
You can also try to add the flag -vv in your CURL command to debug it further and see what's happening when it tries to connect to Bitbucket.org.

Let me know how it goes.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events