How to add many groups to a user via REST-API?

I need to deal with really large number of groups (about 200-600 per user) which get’s assigned programatically using the REST-API of Keycloak-admin.

The only way i figured out until now was to first resolve the group-id (some uuid style string) for every group i want to assign first, by utilizing:
GET /{realm}/groups
and then assign them to a user by an individual call per group to
PUT /{realm}/users/{id}/groups/{groupId}

That takes a lot of time, even if i now use local stored hash-tables for the group-resolving and hopefully my http-client (Guzzle) is reusing the connection so it uses less resources on the target host.

I wonder if there is a more elegant way to assign multiple (bulk) groups to a user in one go?

1 Like