# Rerun the task

Rerun the file specified in the export task.

```text
POST https://moi.matrixorigin.cn/newmoi/export/task/$TASK_ID/rerun
```

## Preparation before calling

First [Query export files](list-export-task-files.md) to confirm the export tasks and failed files to be retried. Prepare a personal access token with access to the target workspace, the target workspace ID, and the export task ID.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$TASK_ID`: The export task ID to be retried, fill in the task ID position in the request address.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/export/task/$TASK_ID/rerun" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "files": [
      "export-file_01"
    ]
  }'
```

Retry all failed files:

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/export/task/$TASK_ID/rerun" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
  }'
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `task_id` | string | Yes | The ID of the export task to rerun. |

## Request body

| Field | Type | Is it required | Description |
| --- | --- | --- | --- |
| `files` | string[] | No | Specifies the export record ID to be re-run; if no or an empty array is passed, all files with failed status in the task will be retried. |

`[]` after a type denotes an array. `[]` in a field path denotes each item in an array.

## Successful response

Returns `200` on success. `data` is `null`, indicating that the rerun request has been accepted; please continue to query the task status and file status to confirm the actual processing results.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": null
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` means the retry request has been successfully accepted. |
| `msg` | string | Success message with value `OK`. |
| `data` | null | The interface does not return new task or file results. |

## Error response

Business failure may be returned with HTTP `200` and `code` other than `OK`.

```json
{
  "code": "ErrServer",
  "msg": "Internal server error",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 24 36 28

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - —
  - The request body cannot be parsed; this compatibility path returns the `error` field instead of the standard envelope.
  - Make sure `files` is a string array.
* - `200`
  - `ErrServer`
  - The task or file record does not exist, a failed retry file was not found, or the dependent resource is unavailable.
  - Query the file status first; when `files` is not specified, it will only be called when there is a failed file in the task.
* - `403`
  - `ErrForbidden`
  - The current identity does not have retry permission.
  - Request permission to retry the export task.
* - `503`
  - `ErrCoreAuthorizeUnavailable`
  - Authorization service is temporarily unavailable.
  - Try again later.
```

## Follow-up operations

After retrying the acceptance, use the same task ID [query task status](get-export-task-state.md) to track the progress.
