Create user on Keycloack from curl command
According to Keycloak's documentation ( Server Admin > The Admin CLI > Basic operations and resource URIs ), the users
endpoint should be:
http://localhost:8080/auth/admin/realms/apiv2/users
So please fix your last URL accordingly.
You can also find a full example on Keycloak's JIRA issue #5383. Note that it is adding the content-type header explicitly as well:
Content-Type: application/json
try this, I added the content type header and modify the url :
#!/bin/bash
echo "* Request for authorization"
RESULT=`curl --data "username=admin&password=Pa55w0rd&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/apiv2/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"[email protected]", "enabled":"true"}'