{"id":7686,"library":"rocketchat-api","title":"Rocket.Chat API Wrapper","description":"rocketchat-api is a Python API wrapper for Rocket.Chat, allowing developers to programmatically interact with Rocket.Chat instances. It provides a convenient interface to various Rocket.Chat API endpoints, abstracting away direct HTTP requests. The library is actively maintained, with a typical release cadence of minor versions every 1-2 months, and its current version is 3.5.0.","status":"active","version":"3.5.0","language":"en","source_language":"en","source_url":"https://github.com/jadolg/rocketchat_API","tags":["rocketchat","api","chat","wrapper","messaging"],"install":[{"cmd":"pip install rocketchat-api","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Handles underlying HTTP communication with the Rocket.Chat server.","package":"requests","optional":false}],"imports":[{"symbol":"RocketChatAPI","correct":"from rocketchat_API.rocketchat import RocketChatAPI"}],"quickstart":{"code":"import os\nfrom rocketchat_API.rocketchat import RocketChatAPI\n\n# Configure connection details and credentials via environment variables for security\nROCKETCHAT_SCHEME = os.environ.get('ROCKETCHAT_SCHEME', 'https')\nROCKETCHAT_HOST = os.environ.get('ROCKETCHAT_HOST', 'demo.rocket.chat')\nROCKETCHAT_PORT = os.environ.get('ROCKETCHAT_PORT', '443') # Note: Port should be string for consistent config\nROCKETCHAT_USER = os.environ.get('ROCKETCHAT_USER', 'your_username')\nROCKETCHAT_PASS = os.environ.get('ROCKETCHAT_PASS', 'your_password')\n\nrocket = RocketChatAPI(settings={\n    'scheme': ROCKETCHAT_SCHEME,\n    'host': ROCKETCHAT_HOST,\n    'port': int(ROCKETCHAT_PORT), # Ensure port is int if expected by library\n    'username': ROCKETCHAT_USER,\n    'password': ROCKETCHAT_PASS\n})\n\n# Example: Get information about the current user\ntry:\n    me_info = rocket.me().json()\n    print(f\"Logged in as: {me_info.get('username')}\")\nexcept Exception as e:\n    print(f\"Error connecting or authenticating: {e}\")\n\n# Example: Send a direct message\ntry:\n    if me_info and 'username' in me_info:\n        # Replace 'otheruser' with a valid Rocket.Chat username to send a message to\n        response = rocket.chat_post_message(room_id='GENERAL', text='Hello from rocketchat-api!').json()\n        print(f\"Message sent status: {response.get('success')}\")\nexcept Exception as e:\n    print(f\"Error sending message: {e}\")","lang":"python","description":"Initializes the RocketChatAPI client using environment variables for credentials and connects to a Rocket.Chat instance. It then demonstrates fetching the current user's information and sending a public message. Ensure you replace 'your_username' and 'your_password' with actual credentials or set the corresponding environment variables."},"warnings":[{"fix":"Catch `RocketApiException` and access error details via its attributes (e.g., `e.error`). Update any conditional logic that inspects exception messages to use these new attributes for robustness.","message":"Starting with v3.0.0, the library's exception handling was reworked. Exceptions now carry more detailed error information. Code relying on generic exception catching or checking specific exception attributes might need updates.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review calls to affected methods and update parameters accordingly. For `users_create_token`, pass the `secret` value. For role management, ensure you're passing the `role_id`.","message":"In v2.1.0, several API method signatures changed. `rooms_upload` was removed. `addUserToRole` and `removeUserFromRole` now require `role_id` instead of `role_name`. `users_create_token` no longer accepts `username` but requires a `secret` parameter.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Remove `.json()` calls from the end of API method invocations. The methods directly return the parsed JSON response. For example, change `rocket.me().json()` to `rocket.me()`.","message":"As of v2.0.0, API methods no longer return the raw `requests` response object directly. Instead, they return the JSON body of the response, often as a dictionary or list. Calling `.json()` on the return value will result in an `AttributeError`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Convert the port string to an integer before passing it to the `RocketChatAPI` constructor, e.g., `port=int(os.environ.get('ROCKETCHAT_PORT', 443))`.","message":"When providing a custom port for the Rocket.Chat instance, ensure it is passed as an integer in the `settings` dictionary during `RocketChatAPI` initialization, even if read from environment variables (which are strings).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remove the `.json()` call. The API method already returns the dictionary or list directly. Example: Change `rocket.me().json()` to `rocket.me()`.","cause":"Attempting to call `.json()` on the result of an API method after upgrading to v2.0.0 or later. Methods now directly return the JSON-parsed response.","error":"AttributeError: 'dict' object has no attribute 'json'"},{"fix":"Double-check your `ROCKETCHAT_USER`, `ROCKETCHAT_PASS` (or `ROCKETCHAT_AUTH_TOKEN`), `ROCKETCHAT_HOST`, `ROCKETCHAT_SCHEME`, and `ROCKETCHAT_PORT` environment variables or settings passed to `RocketChatAPI`. Verify network connectivity to the Rocket.Chat server.","cause":"Incorrect username, password, or authentication token, or an invalid Rocket.Chat server URL/port.","error":"rocketchat_API.rocketchat.RocketChatAPIException: Unauthorized"},{"fix":"Verify the username or user ID is correct. Ensure the user associated with the API credentials has the necessary permissions to view or interact with the target user.","cause":"Attempting to access information or perform an action for a user that does not exist on the Rocket.Chat instance or for whom the authenticated user lacks permissions.","error":"rocketchat_API.rocketchat.RocketChatAPIException: User not found"},{"fix":"Update the method call to use `role_id` instead of `role_name`. You may need to fetch the `_id` of the role first via the roles API.","cause":"Calling `addUserToRole` (or `removeUserFromRole`) with `role_name` after upgrading to v2.1.0, which changed the parameter to `role_id`.","error":"TypeError: addUserToRole() got an unexpected keyword argument 'role_name'"},{"fix":"Consult the `rocketchat-api` library documentation and Rocket.Chat API documentation for the correct method name and available endpoints. If a method was deprecated, look for an alternative.","cause":"Attempting to call an API method that either does not exist, has been removed from the Rocket.Chat API (or the library wrapper), or the user lacks permissions for.","error":"rocketchat_API.rocketchat.RocketChatAPIException: MethodNotFound"}]}