2
votes

I'm not able to delete realm via REST API on Keycloak 8.0.2.

My Keycloak runs on localhost:38080. I followed this documentation https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_realms_admin_resource, see "Delete the realm" paragraph. First, I got token for admin user at http://localhost:38080/auth/realms/master/protocol/openid-connect/token

curl --location --request POST 'localhost:38080/auth/realms/master/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin' \
--data-urlencode 'client_id=vga_tests' \
--data-urlencode 'grant_type=password'

Then I used the token and tried to delete the example realm by this call

curl --location --request DELETE 'localhost:38080/auth/Example' \
--header 'Authorization: Bearer <TOKEN HERE>' \
--header 'Content-Type: application/json' \
--data-raw ''

(Note: curl commands are exported Postman calls)

I got this 404 response

{
    "error": "RESTEASY003210: Could not find resource for full path: http://localhost:38080/auth/Example"
}

What am I doing wrong?

2

2 Answers

3
votes

The documentation is incorrect, the address I needed to send the DELETE request to is localhost:38080/auth/admin/realms/example

curl command:

curl --location --request DELETE 'localhost:38080/auth/admin/realms/example' \
--header 'Authorization: Bearer <TOKEN HERE>' \
--header 'Content-Type: application/x-www-form-urlencoded'
0
votes

Alternatively, using the CLI interface (search for "deleting a realm"), you can do:

$ kcadm.sh delete realms/example