Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete Keycloak realm via REST API

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?

like image 458
Michal Krasny Avatar asked Oct 22 '25 04:10

Michal Krasny


1 Answers

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'
like image 169
Michal Krasny Avatar answered Oct 24 '25 20:10

Michal Krasny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!