# Retry workflow jobs in batches

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

Retry specified executions in batches for a scheduled job, or retry all failed executions under the scheduled job. Accepting the request by the interface does not mean that all jobs have been completed.

```text
POST https://moi.matrixorigin.cn/newmoi/workflow/v2/workflow-apps/{workflow_id}/executions/batch-retry
```

## Preparation before calling

First [query the workflow job list](../workflow-jobs/list-workflow-jobs.md) to confirm the scheduled job and execution scope to be retried. Prepare a personal access token and target workspace ID that has access to the target workspace.

You must choose one of `execution_ids` and `all_failed: true`: the former retries the specified execution, and the latter retries all failed executions in the source scheduled job.

## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>workflow_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>Workflow ID.</dd></div>
  <div class="mo-api-field"><dt><code>source_dispatch_job_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>Source scheduled job ID.</dd></div>
  <div class="mo-api-field"><dt><code>execution_ids</code><span class="mo-api-field__type">string[]</span></dt><dd>List of execution IDs to retry.</dd></div>
  <div class="mo-api-field"><dt><code>all_failed</code><span class="mo-api-field__type">boolean</span></dt><dd>Whether to retry all failed executions under the source scheduled job.</dd></div>
  <div class="mo-api-field"><dt><code>request_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The unique identifier of this batch request.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Request example</p>
```

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workflow/v2/workflow-apps/$WORKFLOW_ID/executions/batch-retry" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "source_dispatch_job_id": "'"$SOURCE_DISPATCH_JOB_ID"'",
    "all_failed": true,
    "request_id": "<REQUEST_ID>"
  }'
```

:::
::::

## Successful response

Returns `200` on success. `data` returns the acceptance status of this batch retry; `replayed` is `true`, indicating that the service identifies it as a repeated submission of the same request.


The response fields are as follows.

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>OK when successful.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>OK when successful.</dd></div>
  <div class="mo-api-field"><dt><code>data.source_dispatch_job_id</code><span class="mo-api-field__type">string</span></dt><dd>Source scheduled job ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.dispatch_job_id</code><span class="mo-api-field__type">string</span></dt><dd>The ID of the scheduled job created or reused in this batch retry.</dd></div>
  <div class="mo-api-field"><dt><code>data.status</code><span class="mo-api-field__type">string</span></dt><dd>The current status of batch retry requests.</dd></div>
  <div class="mo-api-field"><dt><code>data.accepted_count</code><span class="mo-api-field__type">integer</span></dt><dd>The number of executions that will be retried this time.</dd></div>
  <div class="mo-api-field"><dt><code>data.replayed</code><span class="mo-api-field__type">boolean</span></dt><dd>Whether it is a repeated request for the same request_id.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Successful response example</p>
```

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "source_dispatch_job_id": "dispatch-source-001",
    "dispatch_job_id": "dispatch-retry-001",
    "status": "waiting",
    "accepted_count": 1,
    "replayed": false
  }
}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Error response example</p>
```

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

:::
::::

## Follow-up operations

[View workflow jobs](../workflow-jobs/list-workflow-jobs.md) to check the execution status of the retry job.
