Skip to content

Latest commit

 

History

History
122 lines (77 loc) · 3.11 KB

users.md

File metadata and controls

122 lines (77 loc) · 3.11 KB

Users API

users.create

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
user = session.users.create('new_username', '[email protected]', 'New User', '123456',
                     active: true, send_welcome_email: false)

Optional parameters for create are:

:active, :roles, :join_default_channels, :require_password_change, :send_welcome_email, :verified, :custom_fields

users.createToken

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
user = session.users.create('new_username', '[email protected]', 'New User', '123456',
                     active: true, send_welcome_email: false)
token = session.users.create_token(user_id: user.id)

Either user_id (RocketChat's ID) or username can be used to target another user.

users.update

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
user = session.users.update('LAjzCDLqggCT7B82M',
  email: '[email protected]',
  name: 'Updated Name',
  roles: ['user', 'moderator']
)

Optional parameters for update are:

:username, :email, :password, :name, :active, :roles, :join_default_channels, :require_password_change, :send_welcome_email, :verified, :custom_fields

users.info

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
user = session.users.info(username: 'some_username')

Either user_id (RocketChat's ID) or username can be used.

users.getPresence

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
presence_status = session.users.get_presence(username: 'some_username')

Either user_id (RocketChat's ID) or username can be used.

users.delete

To delete a user, the same options as an info request can be used (user_id or username).

users.list

N.B. list is also used for searching/querying

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
users = session.users.list(query: { email: '[email protected]' })

users.resetAvatar

N.B. available since 0.55.0

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
success = session.users.reset_avatar

There are optional parameters user_id and username, that work if the setting user is allowed to set other's avatar.

users.setAvatar

require 'rocketchat'

rocket_server = RocketChat::Server.new('http://your.server.address/')
session = rocket_server.login('username', 'password')
success = session.users.set_avatar('http://image_url')

There is an optional parameter user_id, that works if the setting user is allowed to set other's avatar.