API changes in 5.0? / unable to set users.setPreferences

Description

in RocketChat pre 5.x User Settings (for example idleTImeLimit) could be set with the following curl

curl -H "X-Auth-Token: ${TOKEN}" \ 
     -H "X-User-Id: ${ADMIN_USER_ID}" \
     -H "Content-type:application/json" \
     http://localhost:3000/api/v1/users.setPreferences  \ 
     -d '{ "userId": "'"${id}"'", "data": { "idleTimeLimit":360 } }'

→ this now yields error: {“success”:false,“error”:“must NOT have additional properties [invalid-params]”

getting all set preferences still works as expected:

curl -H "X-Auth-Token: ${TOKEN}" \ 
     -H "X-User-Id: ${ADMIN_USER_ID}" \
     -H "Content-type:application/json" \
     http://localhost:3000/api/v1/users.setPreferences  \ 
     -d '{ "userId": "'"${id}"'", "data": {  } }'

taken from:

→ same with /api/v1/users.saveUserPreferences

will dig in an try around, any help would be most welcome though :slight_smile:

Server Setup Information

  • Version of Rocket.Chat Server: 5.0.6

Any additional Information

Hi @Snek !

Thanks for pointing this out! There are indeed some inconsistencies with this API doc.

First, it has the wrong endpoint on the beginning of the page and the correct one at the examples

it’s not
/api/v1/users.saveUserPreferences
but
/api/v1/users.setPreferences

Second, the parameters are not required. You can call for example:

curl --request POST \
  --url http://localhost:3000/api/v1/users.setPreferences \
  --header 'Content-Type: application/json' \
  --header 'X-Auth-Token: Gh0h6FY3xiLrE4jdmDJKcXDfsFPP2hZcM8zGOAPt574' \
  --header 'X-User-Id: FC29Nk7genkZoWheE' \
  --data '{
		"userId": "XDRokePKo3LckFcaJ",
    "data": { "language": "pt-br", "highlights": [ "some word"]}
 }'

Apart from that, I was able to call the API without errors at latest 5.1.2
Please, consider upgrading to this version, as there is a security hotfix on it

By the way, I have just sent the mentioned changes to the doc, it should be available anytime soon.

Thanks!

Hello @dudanogueira

Thank you for your update, i have tried it with your example but ran into the same issue.
→ it seems the Problem is a specific setting: "idleTimeLimit": 360
other Settings work fine, also with my previous method, but i get an error when attempting to set idleTimeLimit :thinking: ?

is this a bug? can you try changing idleTimeLimit and see if it works for you?

Edit: it also doesnt like: "desktopNotificationDuration":0

You are right.

Sorry, missed this. :see_no_evil: There is a bug here! :beetle:

A workaround is to use the realtime api methods as a rest api.
yes, we can do that :sunglasses:

It would go something like this:

curl --request POST \
  --url http://localhost:3000/api/v1/method.call/saveUserPreferences \
  --header 'Content-Type: application/json' \
  --header 'X-Auth-Token: Gh0h6FY3xiLrE4jdmDJKcXDfsFPP2hZcM8zGOAPt574' \
  --header 'X-User-Id: FC29Nk7genkZoWheE' \
  --data '{"message":"{\"msg\":\"method\",\"id\":\"RANDOM_ID_HERE\",\"method\":\"saveUserPreferences\",\"params\":[{\"idleTimeLimit\":3602,\"useLegacyMessageTemplate\":false}]}"}'

the trade off here is that you cannot set the settings for another user :frowning:

Can you open an Issue for that? Also, linking to this forum thread?

Thanks!

I have created: Rest API / some users.setPreferences cannot be set anymore in Rocket.Chat 5.x · Issue #26923 · RocketChat/Rocket.Chat · GitHub

1 Like