Managing multiple user groups via REST API

Hello there. I’m trying to figure out if is there any way to change multiple groups of a specific user via REST API.

When I create a user via POST to endpoint {{keycloak_url}}/admin/realms/{{realm}}/users, I can pass an array containing the groups that I want for that user and it works perfectly!

But when I try to update the same user via PUT to endpoint {{keycloak_url}}/admin/relalms/{{realm}}/users/{{userID}}, It updates the user info (email, attributes, etc) but ignores the new array of groups that I passed the same way as I did before.

I already checked the names of groups and it matches with existing groups in my realm, so of course that’s not the problem.

In Keycloak documentation, it says that the PUT {{keycloak_url}}/admin/realms/{{realm}}/users/{{userID}} endpoint can receive an UserRepresentation, wich includes the groups array.

I’m using Keycloak 18.0. Appreciate any help.