Do a backup before doing this. Bulk adding users to groups can end with a headache if things are not done right.
Added users won’t receive any email or notification for being added to new group(s) this way.
Description
Using a combination of data explorer and bulk invites, it is possible to add existing users from groups to other groups easily.
One use case would be to have all users from several groups also in another group to @mention every member of the first groups without having to @mention every “sub-group”.
You may use it with a non-public group for the purpose of having a better overview of all the members belonging to several groups without relying on custom data explorer queries.
You also could use this to fix groups after a migration if needed.
With this tips-and-tricks, you can select users from one or multiple groups and add them in one or multiple other groups.
It is done by using a SQL query which we download the results as a CSV file. The latter will be used for a bulk invite.
Requirements
You need to have the plugin Data Explorer.
If you don’t have it yet, you must be either self-hosted with root access, or a Business or Enterprise customer.
Instructions
Set up the data explorer query
Go to Admin → Plugins → Data Explorer, and create a new query. The query name is at your will
In the query input, paste this SQL code:
--[params]
-- string_list :group_name
-- string_list :new_group_names
SELECT ue.email as "address@email", :new_group_names as "new group"
FROM users u
INNER JOIN group_users gu ON u.id = gu.user_id
INNER JOIN groups g on g.id = gu.group_id
INNER JOIN user_emails ue on u.id = ue.user_id
WHERE g.name IN (:group_name)
AND ue.primary = true
The data explorer screen should now look like this:
If the two inputs group_names
and new_group_names
don’t show up, click Save Changes and reload the page.
The first input will contain the group you want to return the users from.
In my example, we’ll return the users of the group grapes, with the intent of putting them in the group fruits as well.
Download the results as a CSV file
First, run the query to be sure it outputs some users from the group grapes:
Now you’re sure the query works, download the results as a CSV file by clicking the button CSV.
If you check the contents of your CSV file, it should look like this:
address@email,new groups
anon82961384@anonymized.invalid,fruits
anon92619503@anonymized.invalid,fruits
Bulk invite users
Go to Admin → Send Invites → click Bulk Invite, and select the CSV file you downloaded.
Validate the invite by clicking Bulk Invite:

You’ll receive an automated message named “Bulk user invite processed with errors” and containing
[2023-04-05 14:48:08 +0000] Invalid Email 'address@email
.
Don’t worry! This is normal.
The bulk import expects the first line of the CSV file as valid data, which is not here. When we download a CSV from a data explorer query, the first line is meant to contain the headers of a table. It will not prevent the users from being added to groups. You can ignore this unless there are other errors in the log.
Check that the users were added to the target group
Verify that your users from the group grapes were added to the target group fruits.
Here are the users from the group grapes:
The group fruits was empty:
After bulk inviting from my CSV file, the group fruits is properly populated:
Select multiple groups
It is possible to select users from a single or multiple groups and add them to one or multiple groups.
You have to fill in the inputs group_names
and new_group_names
inputs using separators.
Select users from multiple groups
Select users by multiple groups by separating them with a comma ,
:
grapes,cherries
Select multiple groups to which the users will be added
Choose multiple groups by separating them with a semicolon ;
:
fruits;vegetables
Of course, you can select users from 1 group to be added to several others or vice-versa.
There is nothing more to do regarding this, you can download the results as a CSV file and proceed to the bulk invite as described previously in this tutorial.