Keycloak · Arazzo Workflow

Keycloak Upsert a Realm Role

Version 1.0.0

Create a realm-level role if it is missing, update it if it already exists, then read it back.

1 workflow 1 source API 1 provider
View Spec View on GitHub AuthenticationAuthorizationIdentity ManagementOpenID ConnectSecuritySSOArazzoWorkflows

Provider

keycloak

Workflows

upsert-realm-role
Idempotently define a realm-level role and return its stored representation.
Searches the realm for a role by name, updates it when present and creates it when absent, then reads the role back by exact name to confirm the result.
4 steps inputs: attributes, description, realm, roleName outputs: composite, description, roleId, roleName
1
searchRoles
Search the realm's roles for the target name. Keycloak matches substrings here, so a hit is treated only as a signal to take the update branch, not as proof of an exact match.
2
updateExistingRole
Update the role in place, addressed by its exact name rather than by anything the substring search returned. Jumps straight to the read-back so the create branch is not also executed.
3
createNewRole
Create the realm-level role. Keycloak answers 201 with no response body, so the representation is resolved by the read-back step that follows.
4
readBackRole
Read the role by its exact name to return the authoritative stored representation, including the generated id that role mapping calls require.

Source API Descriptions

Arazzo Workflow Specification

Raw ↑
arazzo: 1.0.1
info:
  title: Keycloak Upsert a Realm Role
  summary: Create a realm-level role if it is missing, update it if it already exists, then read it back.
  description: >-
    The role definition half of managing Keycloak declaratively. A pipeline that
    applies a role catalog cannot know whether each role already exists, so this
    workflow searches for the role by name and branches: a match is updated in
    place, a miss is created, and both branches converge on a read-back that
    returns the authoritative representation. The search is deliberately not
    trusted as an exact match, since Keycloak's role search does substring
    matching; the read-back by exact name is what confirms the role the flow
    actually landed on. Every step spells out its request inline so the flow can
    be read and executed without opening the underlying OpenAPI description.
  version: 1.0.0
sourceDescriptions:
- name: rolesApi
  url: ../openapi/keycloak-roles-api-openapi.yml
  type: openapi
workflows:
- workflowId: upsert-realm-role
  summary: Idempotently define a realm-level role and return its stored representation.
  description: >-
    Searches the realm for a role by name, updates it when present and creates it
    when absent, then reads the role back by exact name to confirm the result.
  inputs:
    type: object
    required:
    - realm
    - roleName
    properties:
      realm:
        type: string
        description: The name of the realm to define the role in.
      roleName:
        type: string
        description: The name of the realm-level role (e.g. "billing-admin").
      description:
        type: string
        description: A human readable description of what the role grants.
      attributes:
        type: object
        description: >-
          Optional role attributes, as a map of attribute name to an array of
          string values.
  steps:
  - stepId: searchRoles
    description: >-
      Search the realm's roles for the target name. Keycloak matches substrings
      here, so a hit is treated only as a signal to take the update branch, not
      as proof of an exact match.
    operationId: getRoles
    parameters:
    - name: realm
      in: path
      value: $inputs.realm
    - name: search
      in: query
      value: $inputs.roleName
    - name: max
      in: query
      value: 100
    - name: briefRepresentation
      in: query
      value: false
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      matchedRoles: $response.body
    onSuccess:
    - name: roleExists
      type: goto
      stepId: updateExistingRole
      criteria:
      - context: $response.body
        condition: $.length > 0
        type: jsonpath
    - name: roleMissing
      type: goto
      stepId: createNewRole
      criteria:
      - context: $response.body
        condition: $.length == 0
        type: jsonpath
  - stepId: updateExistingRole
    description: >-
      Update the role in place, addressed by its exact name rather than by
      anything the substring search returned. Jumps straight to the read-back so
      the create branch is not also executed.
    operationId: updateRole
    parameters:
    - name: realm
      in: path
      value: $inputs.realm
    - name: roleName
      in: path
      value: $inputs.roleName
    requestBody:
      contentType: application/json
      payload:
        name: $inputs.roleName
        description: $inputs.description
        attributes: $inputs.attributes
    successCriteria:
    - condition: $statusCode == 204
    onSuccess:
    - name: updated
      type: goto
      stepId: readBackRole
  - stepId: createNewRole
    description: >-
      Create the realm-level role. Keycloak answers 201 with no response body, so
      the representation is resolved by the read-back step that follows.
    operationId: createRole
    parameters:
    - name: realm
      in: path
      value: $inputs.realm
    requestBody:
      contentType: application/json
      payload:
        name: $inputs.roleName
        description: $inputs.description
        attributes: $inputs.attributes
    successCriteria:
    - condition: $statusCode == 201
  - stepId: readBackRole
    description: >-
      Read the role by its exact name to return the authoritative stored
      representation, including the generated id that role mapping calls require.
    operationId: getRole
    parameters:
    - name: realm
      in: path
      value: $inputs.realm
    - name: roleName
      in: path
      value: $inputs.roleName
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      roleId: $response.body#/id
      resolvedRoleName: $response.body#/name
      roleDescription: $response.body#/description
      composite: $response.body#/composite
      containerId: $response.body#/containerId
  outputs:
    roleId: $steps.readBackRole.outputs.roleId
    roleName: $steps.readBackRole.outputs.resolvedRoleName
    description: $steps.readBackRole.outputs.roleDescription
    composite: $steps.readBackRole.outputs.composite

Work with this as data

Every workflow 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 arazzo workflows

4 MCP tools reach this
  • find_arazzoBrowse and filter every workflow in the catalog.
  • 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 workflow
curl "https://apis.io/api/v1/arazzo/keycloak-upsert-realm-role-workflow"
All arazzo workflows
curl "https://apis.io/api/v1/arazzo?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.