# Assign group to user by Admin API (Register)

**URL:** <https://forum.keycloak.org/t/assign-group-to-user-by-admin-api-register/29894>\
**Category:** Getting advice\
**Created:** [April 14, 2025, 1:00pm UTC](https://forum.keycloak.org/t/assign-group-to-user-by-admin-api-register/29894 "2025-04-14T13:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKDragon18](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/skdragon18/32/11939_2.png) [@SKDragon18](https://forum.keycloak.org/u/SKDragon18)\
**Post date:** [April 14, 2025, 1:00pm UTC](https://forum.keycloak.org/t/assign-group-to-user-by-admin-api-register/29894/1 "2025-04-14T13:00:33Z")

</div>

**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?**

---

<div class="post-metadata">

**Author:** ![edewit](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/edewit/32/287_2.png) [@edewit](https://forum.keycloak.org/u/edewit)\
**Post date:** [April 17, 2025, 3:17pm UTC](https://forum.keycloak.org/t/assign-group-to-user-by-admin-api-register/29894/2 "2025-04-17T15:17:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vetall](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/vetall/32/7800_2.png) [@Vetall](https://forum.keycloak.org/u/Vetall)\
**Post date:** [April 24, 2025, 6:26am UTC](https://forum.keycloak.org/t/assign-group-to-user-by-admin-api-register/29894/3 "2025-04-24T06:26:57Z")

</div>

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](mailto:email%22:%22nikola@gmail.com)”,  
“emailVerified”:true,  
“enabled”:true,  
“firstName”:“Никола”,  
“groups”:[“/customer”, “/root/child\_1”, “/root/child\_2”, “/root/child\_3”],  
“lastName”:“Питерский”,  
“username”:“nikola”  
}  
it works properly
