# Repair data privilege operation

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Reprocess a data-privilege change that needs repair or has an unconfirmed result. Repair creates a new change operation; continue tracking its new result.

```text
POST https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/iam/roles/{role_id}/data-privilege-operations/{request_id}:repair
```

## Preparation before calling

First [select a role](../roles/list-roles.md#select-a-role), then [view the data privilege operation](get-data-privilege-operation.md#determine-whether-repair-is-applicable) and confirm it can be repaired. Prepare a [personal access token](../../../../../guides/genesis/api-keys.md) with required workspace permissions and the [target workspace ID](../../../../../guides/ai-studio/resource-center/workspace.md#copy-a-workspace-id).

## Request parameters

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

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/iam/roles/$ROLE_ID/data-privilege-operations/$REQUEST_ID:repair" -H "X-API-Key: $AI_STUDIO_API_KEY" -H "X-Workspace-ID: $WORKSPACE_ID" -H "Content-Type: application/json" -d '{"request_id":"req-001","expected_data_privilege_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_id` | string | Yes | Original data-privilege request ID to repair. |

### Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `request_id` | string | Yes | New caller-generated idempotency request ID for this repair. |
| `expected_data_privilege_version` | integer | Yes | Expected data-privilege version; cannot be less than 0. |

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

## Successful response

Returns the repair operation state. When its state is `applying`, view the new operation with this repair request's `request_id`, not the original request ID in the path.

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

```json
{"code":"OK","msg":"OK","data":{"request_id":"repair-req-001","trace_id":"trace-001","operation_id":"operation-002","audit_event_id":"audit-002","state":"succeeded","data_privilege_version":3,"idempotent_replay":false,"session_invalidation_status":"new_connections_only","matrixone_fact_version":"fact-v3","resource_results":[]}}
```

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

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.request_id` | string | Repair request ID used to view the repair operation. |
| `data.operation_id` | string | Server-generated repair operation ID. |
| `data.audit_event_id` | string | Repair audit event ID. |
| `data.state` | string | Repair state: `applying`, `succeeded`, `failed`, `drifted`, or `unknown`. |
| `data.data_privilege_version` | integer | Data-privilege version after repair. |
| `data.idempotent_replay` | boolean | Whether this is an idempotent replay of the repair request. |
| `data.session_invalidation_status` | string | Session privilege refresh status. |
| `data.matrixone_fact_version` | string | MatrixOne privilege fact version. |
| `data.resource_results` | object array | Repair result for each resource. |
| `data.trace_id` | string | Trace ID. |

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

## Error response

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

```json
{"code":"ErrParamInvalid","msg":"Invalid request parameters","data":null}
```

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

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

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