Keycloak Roles API

Manage realm-level and client-level roles

Operations 8

GET /{realm}/users/{userId}/role-mappings/realm Keycloak Get realm-level role mappings for a user #
POST /{realm}/users/{userId}/role-mappings/realm Keycloak Add realm-level role mappings to a user #
DELETE /{realm}/users/{userId}/role-mappings/realm Keycloak Remove realm-level role mappings from a user #
GET /{realm}/roles Keycloak List realm-level roles #
POST /{realm}/roles Keycloak Create a realm-level role #
GET /{realm}/roles/{roleName} Keycloak Get a realm-level role by name #
PUT /{realm}/roles/{roleName} Keycloak Update a realm-level role #
DELETE /{realm}/roles/{roleName} Keycloak Delete a realm-level role #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/keycloak-roles-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

keycloak-roles-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Keycloak Admin REST Clients Roles API
  description: The Keycloak Admin REST API provides endpoints for managing all aspects of a Keycloak deployment, including realms, users, clients, roles, groups, and identity providers. All endpoints require authentication via a bearer token obtained from the Keycloak token endpoint.
  version: 26.0.0
  contact:
    name: Keycloak
    url: https://www.keycloak.org/
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
servers:
- url: https://{host}/admin/realms
  description: Keycloak Admin REST API
  variables:
    host:
      default: localhost:8080
      description: Keycloak server host and port
security:
- bearerAuth: []
tags:
- name: Roles
  description: Manage realm-level and client-level roles
paths:
  /{realm}/users/{userId}/role-mappings/realm:
    parameters:
    - $ref: '#/components/parameters/realm'
    - $ref: '#/components/parameters/userId'
    get:
      operationId: getUserRealmRoleMappings
      summary: Keycloak Get realm-level role mappings for a user
      tags:
      - Roles
      responses:
        '200':
          description: A list of role representations
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/RoleRepresentation'
    post:
      operationId: addUserRealmRoleMappings
      summary: Keycloak Add realm-level role mappings to a user
      tags:
      - Roles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/RoleRepresentation'
      responses:
        '204':
          description: Role mappings added
    delete:
      operationId: deleteUserRealmRoleMappings
      summary: Keycloak Remove realm-level role mappings from a user
      tags:
      - Roles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/RoleRepresentation'
      responses:
        '204':
          description: Role mappings removed
  /{realm}/roles:
    parameters:
    - $ref: '#/components/parameters/realm'
    get:
      operationId: getRoles
      summary: Keycloak List realm-level roles
      description: Returns a list of all roles defined at the realm level.
      tags:
      - Roles
      parameters:
      - name: search
        in: query
        schema:
          type: string
      - name: first
        in: query
        schema:
          type: integer
      - name: max
        in: query
        schema:
          type: integer
      - name: briefRepresentation
        in: query
        schema:
          type: boolean
          default: true
      responses:
        '200':
          description: A list of role representations
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/RoleRepresentation'
    post:
      operationId: createRole
      summary: Keycloak Create a realm-level role
      tags:
      - Roles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoleRepresentation'
      responses:
        '201':
          description: Role created successfully
  /{realm}/roles/{roleName}:
    parameters:
    - $ref: '#/components/parameters/realm'
    - name: roleName
      in: path
      required: true
      schema:
        type: string
    get:
      operationId: getRole
      summary: Keycloak Get a realm-level role by name
      tags:
      - Roles
      responses:
        '200':
          description: A role representation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoleRepresentation'
        '404':
          description: Role not found
    put:
      operationId: updateRole
      summary: Keycloak Update a realm-level role
      tags:
      - Roles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoleRepresentation'
      responses:
        '204':
          description: Role updated successfully
    delete:
      operationId: deleteRole
      summary: Keycloak Delete a realm-level role
      tags:
      - Roles
      responses:
        '204':
          description: Role deleted successfully
components:
  parameters:
    userId:
      name: userId
      in: path
      required: true
      description: The UUID of the user
      schema:
        type: string
        format: uuid
    realm:
      name: realm
      in: path
      required: true
      description: The name of the realm
      schema:
        type: string
  schemas:
    RoleRepresentation:
      type: object
      description: Representation of a role in Keycloak
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        name:
          type: string
        description:
          type: string
        composite:
          type: boolean
          description: Whether this role is a composite of other roles
        composites:
          type: object
          properties:
            realm:
              type: array
              items:
                type: string
            client:
              type: object
              additionalProperties:
                type: array
                items:
                  type: string
        clientRole:
          type: boolean
        containerId:
          type: string
        attributes:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Access token obtained from the Keycloak token endpoint. Use the master realm admin credentials or a service account with appropriate realm-management roles.