Update User

HTTP MethodURLRequires Auth

POST

/api/v1/users.update

  • To save customFields you must first define the customFields in admin panel (Accounts -> Registration -> Custom fields)

  • To update the password for the user, edit-other-user-password permission must be set using an administrator account (Administration > Permissions).

  • This endpoint requires 2FA with your password. Refer to Call an endpoint with 2FA

Body Parameters

ArgumentExampleDescription

userId*

BsNr28znDkG8aeo7W

The user ID to update.

data*

"data" : {}

The object that includes the user information to update with the following parameters. Note: If you provide an empty object, the user details are returned.

email

example@example.com

The email address for the user.

name

Example User

The display name of the user.

password

pass@w0rd

The password for the user.

username

example

The username for the user.

active

false

Whether the user is active, which determines if they can login or not.

roles

["moderator", "user", "653fb63ba2f73c7460e18e90"]

The roles the user has been assigned. The default value is user.

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.

joinDefaultChannels

false

Whether the user should join the default channels.

requirePasswordChange

true

Whether the user should be required to change their password when they login.

sendWelcomeEmail

true

Whether the user should get a welcome email.

verified

true

Whether the user's email address should be verified.

customFields

{ twitter: '@example' }

Any custom fields the user should have on their account.

Example Call

curl -H "X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq" \
     -H "X-User-Id: aobEdbYhXfu5hkeqG" \
     -H "Content-type:application/json" \
     http://localhost:3000/api/v1/users.update \
     -d '{"userId": "BsNr28znDkG8aeo7W", 
          "data": { 
               "name": "new name", 
               "email": "newemail@user.tld" }}'

Example Response

{
   "user":{
      "_id": "BsNr28znDkG8aeo7W",
      "createdAt": "2016-09-13T14:57:56.037Z",
      "services": {
         "password": {
            "bcrypt": "$2a$10$5I5nUzqNEs8jKhi7BFS55uFYRf5TE4ErSUH8HymMNAbpMAvsOcl2C"
         }
      },
      "username": "uniqueusername",
      "emails": [
         {
            "address": "newemail@user.tld",
            "verified": false
         }
      ],
      "type": "user",
      "status": "offline",
      "active": true,
      "roles": [
         "user"
      ],
      "_updatedAt": "2016-09-13T14:57:56.175Z",
      "name": "new name",
      "customFields": {
         "twitter": "userstwitter"
      }
   },
   "success": true
}

Change Log

VersionDescription

0.48.0

Renamed to users.update

0.35.0

Added as user.update

Last updated

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