1

How can I get rooms(groups) of a user using python API? I have admin access to rocketchat. I tried:

from rocketchat_API.rocketchat import RocketChat    

rocket = RocketChat(
    ROCKET_CHAT_ADMIN_USERNAME,
    ROCKET_CHAT_ADMIN_PASSWORD,
    server_url=ROCKET_CHAT_HOST)

rocket.users_info(USER_ID)

but it does not contain groups information. I think that I should provide another argument to this method according to the Rest API but I don't know how.

Dandelion
  • 744
  • 2
  • 13
  • 34

2 Answers2

1

You should provide additional keyword arguments like this:

rocket.users_info(user_id=USER_ID, fields='{"userRooms": 1}')

userRooms is the additional field you need to specify according to the Rest API.

Dandelion
  • 744
  • 2
  • 13
  • 34
MyNameIsCaleb
  • 4,409
  • 1
  • 13
  • 31
1

Looking at the REST API, this alternative spotlight method be of interest to you as well:

GET /api/v1/spotlight

Searches for users or rooms that are visible to the user.

https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/spotlight/

And looking at the source code of the Python API:

def spotlight(self, query, **kwargs):
        """Searches for users or rooms that are visible to the user."""
        return self.__call_api_get('spotlight', query=query, kwargs=kwargs)

https://github.com/jadolg/rocketchat_API/blob/master/rocketchat_API/rocketchat.py

Kermit
  • 4,922
  • 4
  • 42
  • 74