title: keycloak add user via api gives NullPointerException and 500 error
body: <p>Working from <a href="https://stackoverflow.com/questions/52440546/create-user-on-keycloack-from-curl-command">Create user on Keycloack from curl command</a>, I adapted the script to my own needs.</p>
  
  <p>The script is</p>
  
  <pre><code>#!/bin/bash
  
  echo "* Request for authorization"
  RESULT=`curl --data "username=admincloak&amp;password=123456&amp;grant_type=password&amp;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"}'
  </code></pre>
  
  <p>All works as expected until adding the user. I get a 500 error</p>
  
  <pre><code>&gt; Content-Length: 81
  &gt; 
  * upload completely sent off: 81 out of 81 bytes
  &lt; HTTP/1.1 500 Internal Server Error 
  &lt; Connection: keep-alive &lt; Content-Length: 0 
  &lt; Date: Thu, 12 Sep 2019 10:38:39 GMT 
  &lt;
  </code></pre>
  
  <p>Looking at the logs fron keycloak, I get</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Any ideas where I am going wrong?</p>