Assigns a specific role to group members.
Note: This function is only relevant for site admins, and group members with group admin permissions.
The assignRole()
function returns a Promise that resolves to the newly-assigned role after it has successfully been assigned. Assigning a role overrides an existing role. For example, assigning a member role to an admin unassigned their admin role.
function assignRole(
groupId: string,
memberIds: Array<string>,
role: GroupRole,
options: AssignRoleOptions,
): Promise<AssignRoleResponse>;
Group ID.
Member IDs.
Max: 100 member IDs
Role to assign.
import { roles } from "wix-groups.v2";
// Sample ID values:
// memberIds: ['7fe8e9e1-d050-4c86-9684-e7f231600a34'],
// groupId: '0261a737-2361-4468-a3b1-5ec2b0667836.'
//
// Sample role value:
// role: 'ADMIN'
//
export function assignRole(groupId, memberIds, role) {
return roles
.assignRole(groupId, memberIds, role)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
}
/* Promise resolves to:
* role: "ADMIN"
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.