# Update role lifecycle

Enable or disable a specified role. Changing the role state affects later role assignment and authorization management.

```text
PUT $CLOUDSIGMA_API_BASE/workspaces/{workspace_id}/iam/roles/{role_id}/lifecycle
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [select the role](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/users-and-permissions/roles/list-roles.html.md#select-a-role), confirm that its state can be changed, and prepare the change using the current state in the list.

## Request parameters

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Input example

```bash
curl -X PUT "$CLOUDSIGMA_API_BASE/workspaces/$WORKSPACE_ID/iam/roles/$ROLE_ID/lifecycle" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"request_id":"req-001","target_state":"disabled","reason_code":"temporary_suspension","expected_lifecycle_version":1}'
```

:::::
:::::{tab-item} Parameter description

### Path parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| workspace_id | string | Yes | Target workspace ID. |
| role_id | string | Yes | Target role ID. |

### Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| request_id | string | Yes | Request ID. |
| target_state | string | Yes | Target state. Must be `active` or `disabled`. |
| reason_code | string | Yes | Change reason code. |
| expected_lifecycle_version | integer | Yes | Expected role lifecycle version. Must be greater than `0`. |

:::::
::::::
:::::::

## Successful response

On success, returns the changed role state and new lifecycle version. Replaying the same request ID with the same content does not apply the state change again.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{"code":"OK","msg":"OK","data":{"role":{"workspace_id":"workspace-001","role_id":"role-001","role_name":"analyst","description":"Data analysis role","lifecycle_state":"disabled","lifecycle_version":4,"system_role":false},"idempotent_replay":false}}
```

:::::
:::::{tab-item} Field details

| Field | Type | Description |
| --- | --- | --- |
| code | string | `OK` on success. |
| msg | string | `OK` on success. |
| data.role | object | Role summary after the state change. |
| data.role.lifecycle_state | string | Current lifecycle state. |
| data.role.lifecycle_version | integer | Updated lifecycle version. |
| data.idempotent_replay | boolean | Whether this is an idempotent replay of the same request. |

:::::
::::::
:::::::

## Error response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{"code":"ErrParamInvalid","msg":"请求参数无效","data":null}
```

:::::
:::::{tab-item} Field details

| Field | Type | Description |
| --- | --- | --- |
| code | string | Error code. |
| msg | string | Error message. |
| data | null | — |

:::::
::::::
:::::::
