# Replay executions

> Replay chosen runs (workflow_execution_ids, or a query) with a replay mode (metadata.run_mode_details.run_mode), each with its own version or the version given.

Source: https://docs.stacksync.com/api-reference/workflows/runs/replay_workflow_runs

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/id/{workflow_id}/executions/batch-create`

- Operation: `replay_workflow_runs`
- Resource: Workflow runs
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |
| `workflow_id` | string (uuid) | Yes | The workflow. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string \| null | No | Region of the workflow: besg or usnv. Required, except when List workflow runs reads several workflows through options.workflows |

## Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string \| null | No | Makes the create retry-safe for 24 hours: a retry with the same key answers the resource the first call created, with the Idempotent-Replayed: true header, and creates nothing. 1 to 255 visible ASCII characters. The same key with a different request answers 422; while the first call still runs, 409. |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `workflow_execution_ids` | any | No |  |
| `query` | any | No |  |
| `query_string` | any | No |  |
| `search_options` | any | No |  |
| `metadata` | any | No |  |
| `workflow_version` | any | No |  |
| `workflow_trigger_module_id` | any | No |  |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `total_requested` | integer | Yes |  |
| `total_succeeded` | integer | Yes |  |
| `total_failed` | integer | Yes |  |
| `errors` | array of object (ReplayError) | Yes |  |
| `errors[].error` | string \| null | No |  |
| `errors[].message` | string \| null | No |  |
| `run_ids` | array of string, default [] | No |  |
| `resolved_count` | integer \| null | No |  |
| `replay_batch_id` | string \| null | No |  |

### 204 No Content

No body.

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/id/{workflow_id}/executions/batch-create?region=usnv" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "workflow_execution_ids": [
    "8d4f2a6c-1e3b-4c7a-9f05-6b2d8e1a3c47"
  ]
}'
```

## Example response (200)

```json
{
  "total_requested": 0,
  "total_succeeded": 0,
  "total_failed": 0,
  "errors": [
    {
      "error": "<error>",
      "message": "<message>"
    }
  ],
  "run_ids": [],
  "resolved_count": 0,
  "replay_batch_id": "<replay_batch_id>"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string }` |
| 403 | Forbidden | `{ "error": string }` |
| 404 | Not Found | `{ "error": string }` |
| 409 | Conflict | `{ "error": string }` |
| 422 | Unprocessable Content | `{ "error": string }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List execution logs](https://docs.stacksync.com/api-reference/workflows/runs/list_workflow_runs)
- [List workflow run step logs](https://docs.stacksync.com/api-reference/workflows/runs/list_workflow_run_logs)
- [Get export capabilities](https://docs.stacksync.com/api-reference/workflows/runs/get_workflow_run_export_capabilities)
- [Replay executions by filter](https://docs.stacksync.com/api-reference/workflows/runs/replay_workflow_runs_by_filter)
- [Resolve executions by filter](https://docs.stacksync.com/api-reference/workflows/runs/resolve_workflow_runs_by_filter)