-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create_user returns 400 error #44
Comments
Could you give us more info about your environemnt? What version of rocket.chat you are using ? What payload you are sending ? |
Hi there - I work with ard900. We are both using OS X and installed the latest version of rocket-python (fresh install via pip). Here's the code (with passwords and URLs altered): from rocketchat.api import RocketChatAPI
def send_rc_message(api, message):
api.send_message(message, 'expected_move_breakouts')
def init_rocket_chat():
api = RocketChatAPI(settings={'username': 'xxx@xxxxxxxx.com', 'password': 'XXXXXXX',
'domain': 'https://chat.xxxxxxxxx.com'})
return api
api = init_rocket_chat()
def add_user(api, email, name, password, username):
api.create_user('email',
'name',
'password',
'username',
active=True,
roles=['user'],
join_default_channels=True,
require_password_change=False,
send_welcome_email=False,
verified=False,
customFields=None)
add_user(api, 'xxxxxx@gmail.com','Ard9','12344321XX','secret-password') Output: HTTPError Traceback (most recent call last) in add_user(api, email, name, password, username) /Users/michael/anaconda3/lib/python3.6/site-packages/rocketchat/api.py in create_user(self, email, name, password, username, **kwargs) /Users/michael/anaconda3/lib/python3.6/site-packages/rocketchat/calls/base.py in call(self, *args, **kwargs) /Users/michael/anaconda3/lib/python3.6/site-packages/requests/models.py in raise_for_status(self) HTTPError: 400 Client Error: Bad Request for url: https://chat.XXXXXXX.com/api/v1/users.create |
First problem which I see is using constant string instead of function parameters here: def add_user(api, email, name, password, username):
api.create_user('email', # <- here
'name', # <- here
'password', # <- here
'username', # <- here
active=True,
roles=['user'],
join_default_channels=True,
require_password_change=False,
send_welcome_email=False,
verified=False,
customFields=None) |
Yeah I can't believe we both didn't see that - LOL - that's what copy/paste gets you :-) Fixed it: def add_user(api, email, name, password, username):
api.create_user(email,
name,
password,
username,
active=True,
roles=['user'],
join_default_channels=True,
require_password_change=False,
send_welcome_email=False,
verified=False,
customFields=None) but it's still throwing the same error for some reason: HTTPError Traceback (most recent call last) in add_user(api, email, name, password, username) /Users/michael/anaconda3/lib/python3.6/site-packages/rocketchat/api.py in create_user(self, email, name, password, username, **kwargs) /Users/michael/anaconda3/lib/python3.6/site-packages/rocketchat/calls/base.py in call(self, *args, **kwargs) /Users/michael/anaconda3/lib/python3.6/site-packages/requests/models.py in raise_for_status(self) HTTPError: 400 Client Error: Bad Request for url: https://chat.xxxxxxxx.com/api/v1/users.create |
Hi again - it seems you may have misunderstood my latest response. The problem persists even though I fixed the params. Can you please take another look? |
Just change |
It's already fixed so from now you can avoid setting customFields if you don't use it. If you have any problem just reopen this issue or create new one. |
Yes that worked - thanks a lot for fixing this! |
I've the similar problem when using the create_user api.
Where as from the logs of rocket chat on my server shows: {"level":35,"time":"2022-02-18T05:09:11.600Z","pid":8,"hostname":"036b252e8186","name":"","name":"API","method":"POST","url":"/api/v1/login","userAgent":"python-requests/2.27.1","length":"29","host":"chat.kodiary.com","remoteIP":"27.34.22.180","responseTime":159} |
@pipozzz Can you update the documentation to create new users. Right now it has customFields=None. It should be customFields={} . |
Thanks for letting me know, I'll fix this soon |
All of the other API calls work fine.
HTTPError: 400 Client Error: Bad Request for url: https://chat.mychatserver.com/api/v1/users.create
The text was updated successfully, but these errors were encountered: