Upsert a Realm Role
A 4-step recipe with Keycloak. We can help you get access.
Recipe · 4 steps
Upsert a Realm Role
with Keycloak · Identity & Access Management
Idempotently define a realm-level role and return its stored representation.
- 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.
- 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.
- Create the realm-level role. Keycloak answers 201 with no response body, so the representation is resolved by the read-back step that follows.
- Read the role by its exact name to return the authoritative stored representation, including the generated id that role mapping calls require.
What you'll need to have ready
- realm: The name of the realm to define the role in.
- roleName: The name of the realm-level role (e.g. "billing-admin").
- description: A human readable description of what the role grants.
- attributes: Optional role attributes, as a map of attribute name to an array of string values.
For your developer
Arazzo workflow keycloak:upsert-realm-role, 4 operations: getRoles → updateRole → createRole → getRole. Specs on APIs.io.