> ## Documentation Index > Fetch the complete documentation index at: https://developer.rocket.chat/llms.txt > Use this file to discover all available pages before exploring further. # Assign Role to User > Assign a role to a user. Optionally, you can set this role to a user for a specific room.
**Permissions required**: - `access-permissions`: Required to modify permissions for various roles - `assign-admin-role`: Permission to assign the admin role to other users ### Changelog | Version | Description | | ---------------- | ------------| |0.70.0 | Added | ## OpenAPI ````json POST /api/v1/roles.addUserToRole { "openapi": "3.0.0", "info": { "version": "1.0.0", "title": "User Management" }, "servers": [ { "url": "https://apiexplorer.support.rocket.chat" } ], "tags": [ { "name": "LDAP" }, { "name": "Permissions" }, { "name": "Roles" }, { "name": "Users" }, { "name": "SAML" } ], "paths": { "/api/v1/roles.addUserToRole": { "post": { "tags": [ "Roles" ], "summary": "Assign Role to User", "description": "Assign a role to a user. Optionally, you can set this role to a user for a specific room.
\n**Permissions required**:\n- `access-permissions`: Required to modify permissions for various roles\n- `assign-admin-role`: Permission to assign the admin role to other users\n\n### Changelog\n| Version | Description |\n| ---------------- | ------------|\n|0.70.0 | Added |", "operationId": "post-api-v1-roles.addUserToRole", "requestBody": { "description": "By default, the three major room roles are available in Rocket.Chat are **Owner**, **Leader**, and **Moderator**. \n[Creating custom roles](https://docs.rocket.chat/use-rocket.chat/user-management/custom-roles) is exclusively available on the Enterprise plan. \nRefer to [Roles](https://docs.rocket.chat/setup-and-configure/roles-in-rocket.chat) for more information.", "content": { "application/json": { "schema": { "type": "object", "properties": { "roleId": { "type": "string", "example": "6579adcf2dd9f9d9514f6", "description": "The ID of an existing role." }, "username": { "type": "string", "description": "The user name.", "example": "test.fun" }, "roomId": { "type": "string", "description": "The ID of the room where the user should be assigned a role, if it is a room role.", "example": "4adb09baa5ad42" } }, "required": [ "roleName", "username" ] }, "examples": { "Example": { "value": { "roleId": "6579adcf2dd9f9d9514f6", "username": "test.fun", "roomId": "64adb09baa5ad4273bfc" } } } } } }, "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "role": { "type": "object", "properties": { "_id": { "type": "string" }, "scope": { "type": "string" }, "description": { "type": "string" }, "mandatory2fa": { "type": "boolean" }, "name": { "type": "string" }, "protected": { "type": "boolean" }, "_updatedAt": { "type": "string" } } }, "success": { "type": "boolean" } } }, "examples": { "Success Example": { "value": { "role": { "_id": "auditor-log", "scope": "Users", "description": "", "mandatory2fa": "false", "name": "auditor-log", "protected": "true", "_updatedAt": "2023-07-10T23:20:56.702Z" }, "success": "true" } } } } } }, "400": { "description": "Bad Request", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" }, "error": { "type": "string" }, "errorType": { "type": "string" } } }, "examples": { "Example 1": { "value": { "success": "false", "error": "must have required property 'username' [error-invalid-role-properties]", "errorType": "error-invalid-role-properties" } }, "Example 2": { "value": { "success": "false", "error": "The required \"userId\" or \"username\" param provided does not match any users [error-invalid-user]", "errorType": "error-invalid-user" } }, "Example 3": { "value": { "success": "false", "error": "error-invalid-role-properties" } } } } } }, "401": { "$ref": "#/components/responses/authorizationError" } }, "parameters": [ { "$ref": "#/components/parameters/UserId" }, { "$ref": "#/components/parameters/Auth-Token" } ] } } }, "components": { "responses": { "authorizationError": { "description": "Unauthorized", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string" }, "message": { "type": "string" } } }, "examples": { "Authorization Error": { "value": { "status": "error", "message": "You must be logged in to do this." } } } } } } }, "parameters": { "UserId": { "name": "X-User-Id", "in": "header", "description": "The authenticated user ID.", "required": "true", "schema": { "type": "string" }, "example": "rbAXPnMktTFbNpwtJ" }, "Auth-Token": { "name": "X-Auth-Token", "in": "header", "description": "The authenticated user token.", "required": "true", "schema": { "type": "string" }, "example": "RScctEHSmLGZGywfIhWyRpyofhKOiMoUIpimhvheU3f" } } } } ````