# Run workflow

> Run a workflow now from its input step's test data, replay a finished run (all steps, failed steps, failed steps and the steps after them, up to a step, from a step), or run one step. Follow the run with list-logs.

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

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/{workflow_id}/runs`

- Operation: `run_workflow`
- Resource: Workflows
- 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 (besg \| usnv) | Yes | Region of the resource: besg (Europe) or usnv (United States), as GET /v1/regions lists them |

## 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 |
| --- | --- | --- | --- |
| `mode` | string (run \| replay_all \| replay_failed \| replay_failed_and_dependents \| until_step \| step_only \| from_step), default "run" | No | run: a new run from the input step's test data; the replay modes need from_run_id |
| `version` | string \| null | No | The version run; the latest when absent |
| `from_run_id` | string \| null | No | The finished run whose data is replayed |
| `step_id` | string \| null | No | The step of the until_step, step_only and from_step modes |

## Returns

### 201 Created

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `run_id` | string | Yes |  |
| `workflow_id` | string | Yes |  |
| `workflow_version` | string \| null | No |  |
| `created_time` | string \| null | No |  |

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/{workflow_id}/runs?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "mode": "run"
}'
```

## Example response (201)

```json
{
  "run_id": "<run_id>",
  "workflow_id": "<workflow_id>",
  "workflow_version": "<workflow_version>",
  "created_time": "<created_time>"
}
```

## Errors

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

## 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 workflows](https://docs.stacksync.com/api-reference/workflows/list_workflows)
- [List workflow versions](https://docs.stacksync.com/api-reference/workflows/list_workflow_versions)
- [Get workflow](https://docs.stacksync.com/api-reference/workflows/get_workflow)
- [Get workflow info](https://docs.stacksync.com/api-reference/workflows/get_workflow_info)
- [Create workflow](https://docs.stacksync.com/api-reference/workflows/create_workflow)
- [Create workflow draft](https://docs.stacksync.com/api-reference/workflows/create_workflow_draft)
- [Update workflow](https://docs.stacksync.com/api-reference/workflows/update_workflow)
- [Update workflow options](https://docs.stacksync.com/api-reference/workflows/update_workflow_options)
- [Delete workflow](https://docs.stacksync.com/api-reference/workflows/delete_workflow)
- [Deploy workflow](https://docs.stacksync.com/api-reference/workflows/deploy_workflow)
- [Duplicate workflow](https://docs.stacksync.com/api-reference/workflows/duplicate_workflow)
- [Save workflow draft](https://docs.stacksync.com/api-reference/workflows/save_workflow_draft)
- [Check a workflow email alias](https://docs.stacksync.com/api-reference/workflows/check_workflow_email_alias)