Assign group to user by Admin API (Register)

Is there a way to assign a group to a user directly in the POST /admin/realms/{realm-name}/users registration API?

Currently, to assign a user to a group after registration, I have to follow at least 3 steps:

  1. Call POST /admin/realms/{realm-name}/users to create a new user.
  2. Retrieve the user_id by calling GET /admin/realms/{realm-name}/users?username=....
  3. Retrieve the group_id by calling GET /admin/realms/{realm-name}/groups and searching for the group name.
  4. Finally, use PUT /admin/realms/{realm-name}/users/{user_id}/groups/{group_id} to assign the user to the group.

This process involves multiple API calls, making it cumbersome and inefficient, especially in scenarios where users and groups are created dynamically.

Why is it not possible to assign a group directly in the user registration API (POST /users)?

Is there any roadmap or official workaround that will allow for group assignments during user registration?

You don’t have to search the user after you created them with the API as it returns the id as part of the response. It will save you one request, but there are plans to create a new admin api that will make things like this easier.

1 Like

Hi, it easy possible to assign groups to user in create POST. Groups is List, you have to define each group string like FULL path to root. Catch example:
{
“attributes”: {
“ip_address”:[“123.123.123.123”],
“phone”:[“+79651757301”],
“max_idle_time”:[“300”],
“max_sessions”:[“2”]
},
email":"nikola@gmail.com”,
“emailVerified”:true,
“enabled”:true,
“firstName”:“Никола”,
“groups”:[“/customer”, “/root/child_1”, “/root/child_2”, “/root/child_3”],
“lastName”:“Питерский”,
“username”:“nikola”
}
it works properly