Search.../

addGroupMembers( )

Adds site members to a group.

Description

The addGroupMembers() function returns a Promise that resolves to the newly-added group member after the member has successfully been added.

For SECRET groups, site admins, group admins, and group members can add additional members to their group.

For PUBLIC and PRIVATE groups, only site admins and group admins can add additional members to their group. They can also choose to allow all group members to add a new member to the group. This setting can be found in your site's Dashboard under Groups Application > Your Group > Admin Tools > Member Permissions.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function addGroupMembers(groupId: string, memberIds: Array<string>): Promise<AddGroupMembersResponse>

addGroupMembers Parameters

NAME
TYPE
DESCRIPTION
groupId
string

Group ID.

memberIds
Array<
string
>

IDs of the site members to add to the group.

Returns

Return Type:

Promise<
AddGroupMembersResponse
>
NAME
TYPE
DESCRIPTION
members
Array<
GroupMember
>

New members.

Was this helpful?

Add site members to a group (dashboard page code)

Copy Code
1import { members } from 'wix-groups.v2';
2
3// Sample groupId value: '0261a737-2361-4468-a3b1-5ec2b0667836'
4//
5// Sample memberIds value: ['937cd3db-e9be-4980-93c1-a6d767a11050', '7fe8e9e1-d050-4c86-9684-e7f231600a34']
6
7 async function addGroupMembers(groupId, memberIds) {
8 try {
9 const result = await members.addGroupMembers(groupId, memberIds);
10
11 return result;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16 }
17
18 /* Promise resolves to:
19 * members: [
20 * {
21 * "joinedDate": "Sun Aug 01 2021 12:32:35 GMT+0300"
22 * "memberId": "437cd3db-e9be-4980-93c1-a6d767a11050"
23 * "role": {"value": "ADMIN"}
24 * },
25 * {
26 * "joinedDate": "Tues Jun 30 2019 10:09:33 GMT+0300"
27 * "memberId": "7fe8e9e1-d050-4c86-9684-e7f231600a34"
28 * "role": {"value": "MEMBER"}
29 * }
30 * ]
31 */
32
Add site members to a group (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { members } from 'wix-groups.v2';
3
4// Sample groupId value: '0261a737-2361-4468-a3b1-5ec2b0667836'
5//
6// Sample memberIds value: ['937cd3db-e9be-4980-93c1-a6d767a11050', '7fe8e9e1-d050-4c86-9684-e7f231600a34']
7
8export const addGroupMembers = webMethod(Permissions.Anyone, async (groupId, memberIds) => {
9 try {
10 const result = await members.addGroupMembers(groupId, memberIds);
11
12 return result;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/* Promise resolves to:
20 * members: [
21 * {
22 * "joinedDate": "Sun Aug 01 2021 12:32:35 GMT+0300"
23 * "memberId": "437cd3db-e9be-4980-93c1-a6d767a11050"
24 * "role": {"value": "ADMIN"}
25 * },
26 * {
27 * "joinedDate": "Tues Jun 30 2019 10:09:33 GMT+0300"
28 * "memberId": "7fe8e9e1-d050-4c86-9684-e7f231600a34"
29 * "role": {"value": "MEMBER"}
30 * }
31 * ]
32 */