how to add existing user group to repository on bitbucket with REST API
Asked by ext.momcilo.vasic:

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... :)


Answers:
author: Mark C
body: Hi [@ext.momcilo.vasic](/t5/user/viewprofilepage/user-id/4886043)

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](https://support.atlassian.com/bitbucket-cloud/docs/group-privileges-endpoint/#PUT-group-privileges-on-a-repository) (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
```

![](https://getsupport.atlassian.com/images/icons/emoticons/information.png) Btw, please also make sure you're using an [App password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) (as your password credential) as we recently [deprecated the Atlassian account password](https://bitbucket.org/blog/deprecating-atlassian-account-password-for-git-and-bitbucket-api-activity).

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

Regards,  
Mark C

comments: author: ext.momcilo.vasic
body: 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?


author: Mark C
body: Hi [@ext.momcilo.vasic](/t5/user/viewprofilepage/user-id/4886043)

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](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/)?  
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


Tags: bitbucket-cloud

cloud