Update: The /auth
path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth
from the endpoint calls presented on this answer.
You can import/export realms using the Keycloak Admin REST API. To import use the endpoint:
POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/partialImport
and provide the JSON
representation of the realm. That representation you can get via Admin Console API by click on Realm
> Export
> Export
. Or using the endpoint:
POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/partial-export?exportClients=true&exportGroupsAndRoles=true
Alternatively, for the export/import you can use:
POST <KEYCLOAK_HOST>/auth/admin/realms
and
GET <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>
respectively.
But then you will need to export/import the clients separately:
GET <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/clients
and
POST <KEYCLOAK_HOST>/auth/admin/realms/<REALM_NAME>/clients
and provide the JSON
representation of the clients.
For a practical example on how to use the Rest API have a look at this answer. That answer is about using the API to create protocols mappers but you can easily adapt it to your use-case.