How to perform rest call for unassign role?

I want to perform a rest call for unassign realm role for an user.
Keycloak provide below api to perform unassign role
http://localhost:8080/admin/realms/portal-realm/users/{userId}/role-mappings/realm
request body :
[
{
“id”: “roleId”,
“name”: “roleName”
}
]
My code :
String url = keycloakBaseUrl + “/admin/realms/” + keycloakRealm + “/users/” + userId + “/role-mappings/realm”;
HttpHeaders headers1 = new HttpHeaders();
headers1.setContentType(MediaType.APPLICATION_JSON);
headers1.setBearerAuth(authorizationToken);
HttpEntity<List> request = new HttpEntity<>(deleteRolesList, headers1);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
try {
ResponseEntity response1 = restTemplate.exchange(builder.toUriString(), HttpMethod.DELETE, request, String.class);
if (response1.getStatusCode() != HttpStatus.NO_CONTENT) {
logger.error(“Error while deleting roles: {}”, response1.getBody());
return new ResponseEntity<>(Constants.ERROR_DURING_ROLE_DELETION, HttpStatus.INTERNAL_SERVER_ERROR);
}
It’s does not work… Please help me

See the doc for that method: Keycloak Admin REST API

It looks like it takes a single RoleRepresentation rather than an array.

Also, when I’m stumped on using the Admin API, I always go to the Admin UI, open the browser dev tools to the network tab and look at the request/response as I perform the function I’m looking to do. Helps me debug my request against something that works.