assignRole( )


Assigns a 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 unassigns their admin role.

Method Declaration
Copy
function assignRole(
  identifiers: Identifiers,
  role: string,
  options: Options,
): Promise<Role>;
Method Parameters
identifiersIdentifiersRequired

Group ID and member IDs.


rolestringRequired

Group member role to assign. One of:

  • "MEMBER": Group member.
  • "ADMIN": Group admin.

optionsOptions

Authorization options.

Returns
Return Type:Promise<Role>
Assign a role to a group member
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { roles } from "wix-groups-backend"; // Sample identifiers value: // { // memberIds: ['7fe8e9e1-d050-4c86-9684-e7f231600a34'], // groupId: '0261a737-2361-4468-a3b1-5ec2b0667836.' // } // // Sample role value: // 'ADMIN' // // Sample options value: // { // suppressAuth: true // } export const assignRole = webMethod( Permissions.Anyone, (identifiers, role, options) => { return roles .assignRole(identifiers, role, options) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); }, ); /* Promise resolves to: * role: "ADMIN" */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?