Skip to content
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

Match error: Unknown key in field username. in users.setAvatar rest call #7509

Closed
mojtab23 opened this issue Jul 17, 2017 · 10 comments · Fixed by #7620
Closed

Match error: Unknown key in field username. in users.setAvatar rest call #7509

mojtab23 opened this issue Jul 17, 2017 · 10 comments · Fixed by #7620
Assignees
Milestone

Comments

@mojtab23
Copy link

mojtab23 commented Jul 17, 2017

Rocket.Chat Version: 0.57.2
Running Instances: 1
DB Replicaset OpLog: enabled
Node Version: v4.8.2

According doc https://rocket.chat/docs/developer-guides/rest-api/users/setavatar
I'm trying to call (/api/v1/users.setAvatar) to set user avatar but I get this error :
{
"success": false,
"error": "Match error: Unknown key in field username"
}
when I change username to userId and test It works but with username it's not working.

@graywolf336
Copy link
Contributor

Please show an example command of how you are able to reproduce this.

@localguru
Copy link
Contributor

localguru commented Jul 17, 2017

This is working fine for me on 0.57.1

curl -H "X-Auth-Token: mytoken" -H "X-User-Id: myuserid" \
-F "image=@hubot.jpg" https://myserver/api/v1/users.setAvatar

How do you set the "username"?

@graywolf336
Copy link
Contributor

@localguru you even tried setting the avatar to another user by providing their username?

@localguru
Copy link
Contributor

localguru commented Jul 17, 2017

@graywolf336 no, I only tested to change my own avatar. How do I pass the "username" via curl?

If I try - as admin - to change another user's avatar by "userid" I get an error:

{
  "status": "error",
  "message": "You must be logged in to do this."
}

Shouldn't that be possible as admin? But through the webinterface there is also no way for changing avatars of other users as admin.

@graywolf336
Copy link
Contributor

What command was you using to do it? As it is possible, we developed it and tested it a while back.

@localguru
Copy link
Contributor

Same as above just with the userid of another user

curl -H "X-Auth-Token: my-admin-user-token" -H "X-User-Id: another-user-id" \
-F "image=@hubot.jpg" https://myserver/api/v1/users.setAvatar

@graywolf336
Copy link
Contributor

That's why then, that is the incorrect usage. Check the documentation: https://rocket.chat/docs/developer-guides/rest-api/users/setavatar

@localguru
Copy link
Contributor

Sorry, don't understand. Could you post an example please.

@graywolf336
Copy link
Contributor

You always have to use your own user id when calling it. However, some api endpoints allow passing in a userId: 'id' or username: 'uusernamehere' in the body of the call. That is what I'm talking about

@W0olFy
Copy link

W0olFy commented Jul 18, 2017

Hi all.

I can confirm that in current version 0.57.2 api request users.setAvatar not working if you use username parameter in payload of request.

Example:

curl -H "X-Auth-Token: adminauthtoken" \
     -H "X-User-Id: adminuserid" \
     -H "Content-type:application/json" \
     -d '{"username": "username", "avatarUrl": "http://domain.tld/link/to/avatars/user_avatar.jpg"}' \
     http://my_rocketchat_instance/api/v1/users.setAvatar

Result:

{
  "success": false,
  "error": "Match error: Unknown key in field username"
}

Ok, let's try userId instead:

curl -H "X-Auth-Token: adminauthtoken" \
     -H "X-User-Id: adminuserid" \
     -H "Content-type:application/json" \
     -d '{"userId": "userIdhere", "avatarUrl": "http://domain.tld/link/to/avatars/user_avatar.jpg"}' \
     http://my_rocketchat_instance/api/v1/users.setAvatar

Result:

{
  "success": true
}

Good. Now let's look at source:
line 189 of users.js

i don't see here anything about username parameter.

Please correct me if i am wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants