Snek
September 21, 2022, 5:06pm
1
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
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!
Snek
September 22, 2022, 10:27am
4
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 ?
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. There is a bug here!
A workaround is to use the realtime api methods as a rest api.
yes, we can do that
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
Can you open an Issue for that ? Also, linking to this forum thread?
Thanks!
Snek
September 22, 2022, 2:38pm
6
1 Like