
# Update an environment role

`PATCH /v1/roles/{role_id}` · permission `roles:write`

Updates the role with a JSON merge patch (RFC 7396, `Content-Type: application/merge-patch+json`). `If-Match` is required. `key` cannot change. When a role becomes privileged, the external group mappings that point to it stay unapproved and grant nothing until approved with `:approve`. A patch that changes nothing keeps the version. The write is audited as `role.updated`.

## Request

| Field | Type | Required | Description |
|---|---|---|---|
| `role_id` | path | yes | Role ID (`rol_…`). |
| `If-Match` | header | yes | Current `ETag` of the role. |
| `name` | string | no | Display name, up to 128 characters. |
| `description` | string | no | Up to 1024 characters. |
| `is_privileged` | boolean | no | Privileged flag. |
| `assignable_in_self_service` | boolean | no | Whether the role can be assigned in self-service. |

## Response

`200 OK` with the role and its new `ETag`.

```json
{
  "id": "rol_01j9xr7s1t2w6x8y0z2a4b6c8e",
  "organization_id": null,
  "key": "support",
  "name": "Support team",
  "description": "",
  "is_privileged": false,
  "assignable_in_self_service": true,
  "permission_ids": [],
  "created_at": "2026-10-12T09:31:00.123456Z",
  "updated_at": "2026-10-12T10:00:00Z",
  "version": 2
}
```

## Errors

| HTTP | code | When |
|---|---|---|
| 400 | `unknown_field` | The patch contains a field that cannot be written (for example `key`). |
| 404 | `not_found` | The role does not exist in this scope. |
| 412 | `precondition_failed` | `If-Match` does not match the current version. |
| 422 | `validation_failed` | A field is invalid. |
| 428 | `precondition_required` | `If-Match` is missing. |
| 401 | `unauthenticated` | The credential is missing, invalid or revoked. |
| 403 | `insufficient_permissions` | The credential lacks the required permission. |
| 429 | `rate_limited` | The rate limit was exceeded; retry after the `Retry-After` period. |
| 503 | `service_unavailable` | A dependency is temporarily unavailable; retry after the `Retry-After` period. |

## Example

```bash
curl -i -X PATCH "https://api.eu.keenauth.com/v1/roles/rol_01j9xr7s1t2w6x8y0z2a4b6c8e" \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY" \
  -H 'If-Match: "1"' \
  -H "Content-Type: application/merge-patch+json" \
  -d '{"name":"Support team"}'
```
