How to set user attribute value in Keycloak using API?

Viewed 2989

How I can set user attribute value using Keycloak Rest API?

enter image description here

1 Answers

To set a user attribute using the Keycloak Rest API, you use the endpoint:

PUT <KEYCLOAK_HOST>/auth/admin/realms/<YOUR_REALM>/users/<USER_ID>

with the payload

{"attributes":{"<ATTRIBUTE_NAME>":["<ATTRIBUTE_VALUE>"]}}

the <USER_ID> you can get it using the endpoint:

GET <YOUR_KEYCLOAK_DOMAIN>/auth/admin/realms/<YOUR_REALM>/users/?username=<THE_USERNAME>

from the JSON response, extract the field id.

Related