Add everyone to a group
Asked by Maricel Ronquillo:

Hi,

I created a new Bitbucket group and would like to add all our users there. Can't seem to find a way to add users by bulk to groups.

Someone might have tried this before.

TIA


Answers:
author: Patrik S
body: Hello [@Maricel Ronquillo](/t5/user/viewprofilepage/user-id/4292792) ,

Thank you for contacting Atlassian Community. My name is Patrik, I'm with the Bitbucket Cloud Support Team and I'll be helping you on this case!

Although we currently don't have the option to bulk add users into a group using the UI, we do have a **groups**api endpoint available, which you can use to add the users to groups programmatically.

The endpoint is the following :

```
`PUT https://api.bitbucket.org/1.0/groups/{workspace_id}/{group_slug}/members/{uuid}/ --data '{}'`
```

The user calling the API must authenticate with administrative rights for a workspace to access its groups.

For more details about required parameters and examples on how to call this API, you can refer to the following documentation :

* <https://support.atlassian.com/bitbucket-cloud/docs/groups-endpoint/#PUT-new-member-into-a-group>

You can then make a custom script to call this endpoint and add the user in bulk.

A member of our support team helped on building the below python script, that uses the **groups endpoint** to add members to a group in a workspace :

```
from requests import SessionUSERNAME = ''APP_PASSWORD = ''WORKSPACE_ID = ''GROUP_ID = '''''This script will attempt to read a text file "users.txt" in the same working directory as itself where each line is a uuid or email address of the user you wish to add to the above group'''def read_from_text_file() -> str:    with open('users.txt', 'r') as user_list:        for user in user_list:            yield user.strip() #removes any whitespace before or afterdef add_user_to_group(session: Session, user: str):    data = '{}'    endpoint = f'https://api.bitbucket.org/1.0/groups/{WORKSPACE_ID}/{GROUP_ID}/members/{user}'    headers = {'Accept': 'application/json', 'Content-type': 'text/plain'}    r = session.put(endpoint, data=data, headers=headers)    if r.status_code == 200:        print(f'Successfully added {user} to {GROUP_ID}')    else:        print(f'Failed to add {user} to {GROUP_ID} with error code: {r.status_code}\n\t{r.text}')def main():    session = Session()    session.auth = (USERNAME, APP_PASSWORD)    for user in read_from_text_file():        add_user_to_group(session, user)if __name__ == '__main__':    main()
```

Following the steps to run the script:

1. Install [python 3.6](https://www.python.org/downloads/) or higher;

2. Install the **request** package with

```

$ pip3 install requests
```

3. Edit the script and provide your Bitbucket **Username** , [App Password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) for authentication, **Workspace** and **Group**.

4. Create a file **users.txt** where each line is a uuid or email address of the user you wish to add to the above group

5. After following all of these steps, you should be able to run the script with the following command :

```

$ python3 <name of the script file>.py
```

Please note the above script was produced by an individual within our support team and is not directly supported by Atlassian or our Support team as a whole. This is provided on a best efforts basis and is provided as we are trying to assist you as much as possible. We recommend you have your dev team review it and ensure you understand what it is attempting to accomplish before executing it. If you would like to change or add functionality to the script, feel free to do so.  

Hope that helps. Let us know in case you have any questions.

Thanks, [@Maricel Ronquillo](/t5/user/viewprofilepage/user-id/4292792)   
Patrik S

comments: author: Maricel Ronquillo
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309)

Thank you for the above information.

As we need to have it done ASAP, I just manually added the users.

I will keep your suggested solution as I might need this in future.

Best regards,

Maricel


Tags: bitbucket-cloud

cloud