Is it possible to update the value of custom attribute via Keycloak REST API? For example, which endpoint to use and how to construct a request body for the attribute that was created here.
Thanks!
Is it possible to update the value of custom attribute via Keycloak REST API? For example, which endpoint to use and how to construct a request body for the attribute that was created here.
Thanks!
You have to use Keycloak Admin REST API :
PUT {host}/{basepath}/admin/realms/{realm}/users/{id}
e.g.
http://localhost:8080/auth/admin/realms/alumni-realm/users/cd57cfd8-cb1c-4025-abfd-67fe6b784d22
Request Body (JSON) :
{
"attributes": {
"DOB": "1984-07-01"
}
}
Authorization (Bearer Token) :
Use Admin user
access_token for authorization.
If you want to allow User
to update their own profile then you have to grant manage-users
role in Keycloak. (That user will be able to update other users info hence it is not recommended)
You can use the API for user update with sending only the attribute to be changed:
PUT ../realms/{realm}/users/{userID} Body:
{
"attributes": {
"myAttribute": [
"NewValue"
]
}
}
It Cause "ID" change when you update user custom attribute via Keycloak REST API PUT ../realms/{realm}/users/{userID}
and you need to GET /{realm}/users
two times to get new value in the response