Assign Role to User

Assign a role to a user. Optionally, you can set this role to a user for a specific room.

HTTP MethodURLRequires Auth

POST

/api/v1/roles.addUserToRole

Body Parameters

KeyExample ValueDescription

roleName*

guest

The role name. Alternatively, you can use the roleId parameter.

Note:

  • For default roles, the role name and ID are the same. For custom roles, the name and ID are different.

  • If you are setting a custom role for a user, make sure to enter the custom role ID and not the role name.

Refer to Roles for more information.

username*

rocket.chat

The user name.

roomId

dK7vNYXMdHGLdukpL

The room ID for which the user is assigned the role.

By default, the three major room roles available in Rocket.Chat are Owner, Leader, and Moderator. Creating custom roles is an Enterprise workspace feature. Refer Room Roles for more information.

Example Call

curl --location 'http://localhost:3000/api/v1/roles.addUserToRole' \
--header 'x-auth-token: o9UKV2D7A5Ggl2vqgyEcItF-YPj4-R93NlMcA6XnE3B' \
--header 'x-user-id: rbAXPnMktTFbNpwtJ' \
--header 'Content-Type: application/json' \
--data '{
    "roleName": "auditor-log", 
    "username": "test.funke", 
    "roomId": "64adb09baa5ad4273bfc0cbf" 
}'

Example Response

{
    "role": {
        "_id": "auditor-log",
        "scope": "Users",
        "description": "",
        "mandatory2fa": false,
        "name": "auditor-log",
        "protected": true,
        "_updatedAt": "2023-07-10T23:20:56.702Z"
    },
    "success": true
}

Change Log

VersionDescription

0.70.0

Added

Last updated

Rocket.Chat versions receive support for six months after release.