Reputation: 289
I am trying to update users info in Keycloak, I was able to update the user using id provided in the keycloak.
I tried with this endpoint and i was able to update using id
PUT /admin/realms/{realm}/users/{id}
Is there any way by which i can update the same user using the email-id as this is also a unique field? i tried replacing {id} with email-id of user but that gave me a error. Is there any way by which i can update the user using email-id or any other unique field of user
Upvotes: 0
Views: 2075
Reputation: 9633
You can not update User with email-id, Option is to set email-id for username and search with following API. Once found the user then update the user.
GET /admin/realms/{realm}/users
Also note Search operation is not exact match search, searching on [email protected]
will return both [email protected]
, [email protected]
.
Upvotes: 0
Reputation: 869
This is not an available feature on Keycloak actually. You can check the documentation of the REST API here. You can always do the workaround getting all the users, parse it looking for the email you want, extract the ID and finally use it for updating its data.
GET /admin/realms/{realm}/users/
User
, use its #getId()
method.PUT /admin/realms/{realm}/users/{id}
You can have a look at Keycloak's UserRepresentation to know what attributes your User object will need.
If you don't know how to use Gson read their documentation or perform a fast google search.
P.S.: Gson is case sensitive so your attributes should have the same names than the one provided in the JSON object.
Upvotes: 1