Working from Create user on Keycloack from curl command, I adapted the script to my own needs.
The script is
#!/bin/bash
echo "* Request for authorization"
RESULT=`curl --data "username=admincloak&password=123456&grant_type=password&client_id=admin-cli" http://localhost:8080/auth/realms/master/protocol/openid-connect/token`
echo "\n"
echo "* Recovery of the token"
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
echo "\n"
echo "* Display token"
echo $TOKEN
echo "\n"
echo " * user creation\n"
curl -v http://localhost:8080/auth/admin/realms/SpringBootKeycloak/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"username":"abc","firstName":"xyz","lastName":"xyz", "email":"demo2@gmail.com", "enabled":"true"}'
All works as expected until adding the user. I get a 500 error
> Content-Length: 81
>
* upload completely sent off: 81 out of 81 bytes
< HTTP/1.1 500 Internal Server Error
< Connection: keep-alive < Content-Length: 0
< Date: Thu, 12 Sep 2019 10:38:39 GMT
<
Looking at the logs fron keycloak, I get
08:56:22,793 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 6.0.1 (WildFly Core 8.0.0.Final) started in 57125ms - Started 580 of 842 services (560 services are lazy, passive or on-demand)
09:17:27,001 WARN [org.keycloak.events] (default task-4) type=LOGIN_ERROR, realmId=SpringBootKeycloak, clientId=bikes-app, userId=null, ipAddress=127.0.0.1, error=invalid_user_credentials, auth_method=openid-connect, grant_type=password, client_auth_method=client-secret, username=admincloak
11:29:46,321 WARN [org.keycloak.events] (default task-8) type=REFRESH_TOKEN_ERROR, realmId=master, clientId=security-admin-console, userId=null, ipAddress=127.0.0.1, error=invalid_token, grant_type=refresh_token, client_auth_method=client-secret
11:38:39,398 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-8) Uncaught server error: java.lang.NullPointerException
at org.keycloak.keycloak-model-infinispan@6.0.1//org.keycloak.models.cache.infinispan.UserCacheSession.getUserByUsername(UserCacheSession.java:237)
at org.keycloak.keycloak-services@6.0.1//org.keycloak.services.resources.admin.UsersResource.createUser(UsersResource.java:109)
Any ideas where I am going wrong?