# Run Workflow

Start a run and get its id back right away. Execution is asynchronous: poll Get Run to follow it. Needs the workflow:run permission.

`POST https://connect.mindcloud.co/v2/workflows/:workflowId/run`

Permissions: `workflow:run`.

## Parameters

### Path

- `workflowId` (string, required): The id of the workflow to run. It must be enabled.

### Headers

- `X-Company-Id` (string): Optional. The id of the organization to act in. Leave it out to act in the API key's own organization. A key can also act in its child organizations, and, with "Use this key across all of your organizations" on, in every organization its creator can open in the app. List them with GET /v2/companies. Every response's X-Company-Id header names the organization it acted in. See [Organizations](https://mindcloud.co/docs/api/rest/introduction/organizations).

### Body

- `version` (string): "published" (default) or "draft".
  Default: `published`
  Allowed values:
    - `published`
    - `draft`
- `environmentId` (string): The environment to run in, from List Environments.

## Example request

```bash
curl --request POST \
  --url 'https://connect.mindcloud.co/v2/workflows/Wq3kZ8pLx2Nb/run' \
  --header 'Authorization: Bearer $MINDCLOUD_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
  "version": "published",
  "environmentId": "Ev8kT3nW5qLz"
}'
```

## Response fields

- `id` (string): The workflow log id. Poll GET /v2/runs/:runId with this id for the outcome.
- `workflowId` (string): The workflow that was started.
- `status` (string): Always waiting: the run is queued.
  Allowed values:
    - `waiting`
- `version` (string): The version that runs: published or draft.
  Allowed values:
    - `published`
    - `draft`
- `environmentId` (string): The environment it runs in, or null for the default.

## Example response

```json
{
  "success": true,
  "data": {
    "id": "Rm4pQ7sJt1Ve",
    "workflowId": "Wq3kZ8pLx2Nb",
    "status": "waiting",
    "version": "published",
    "environmentId": null
  }
}
```

## Errors

- 400 Bad request (INVALID_QUERY, UNKNOWN_ENVIRONMENT): `VALIDATION_FAILED` / `UNKNOWN_ENVIRONMENT` "Unknown environment id "Ev8kT3nW5qLz". Use GET /v2/environments to list available environments."
- 403 Missing permission (API_KEY_PERMISSION_DENIED, API_KEY_CREATOR_INACTIVE): `FORBIDDEN` / `API_KEY_PERMISSION_DENIED` "This API key needs the workflow:run permission for this operation."
- 404 Workflow not found: `NOT_FOUND` "Workflow "Wq3kZ8pLx2Nb" was not found."
- 409 Workflow cannot run (WORKFLOW_DISABLED, WORKFLOW_NOT_PUBLISHED): `CONFLICT` / `WORKFLOW_NOT_PUBLISHED` "Workflow "Wq3kZ8pLx2Nb" has no published version. Publish it in the app, or pass { "version": "draft" } to run the draft."
- 503 Run could not be queued: `UNAVAILABLE` / `RUN_ENQUEUE_FAILED` "The workflow run could not be queued. Retry the request."
- 503 Run created, start unconfirmed: `UNAVAILABLE` / `RUN_ENQUEUE_UNCONFIRMED` "Run "Rm4pQ7sJt1Ve" was created, but its start could not be confirmed. Check it with GET /v2/runs/Rm4pQ7sJt1Ve instead of retrying, which would start a second run."
