# Run an action

> Run one action of an app on its own, outside any workflow, with a connection and the values of its form: the values are checked against the app's live form, then the app runs them once. A read action (get, list, search...) is open to a viewer; any other can change data in the app and needs an editor. A run the app failed or did not answer is answered with its status. With validate_only, every check runs and the answer tells what would run, nothing runs; with validate_only_for_writes, a read runs and an action that can change data only answers that dry run.

Source: https://docs.stacksync.com/api-reference/connectors/run_connector_module

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

- Operation: `run_connector_module`
- Resource: Connectors
- 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. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region whose catalog to read: besg or usnv |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `module_id` | string, at least 1 characters | Yes | The action, from the actions of GET .../workflows/modules/apps/<app_type> (its current version) |
| `module_version` | string, at least 1 characters | Yes | The action's version, from the same answer |
| `connection_id` | string (uuid) \| null | No | The connection the action uses, from GET .../connections (same region); None for an action that takes none |
| `values` | object | No | The action's form values, as the module form describes them (POST .../workflows/modules/forms) |
| `validate_only` | boolean, default false | No | Run every check of the run (action, role, connection, values against the app's live form) and answer what would run, with whether it only reads, without running it: a refused request answers the error the run would |
| `validate_only_for_writes` | boolean, default false | No | true runs a read action at once and only validates a write action (as validate_only would); false runs any action |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `module_id` | string | Yes |  |
| `module_version` | string | Yes |  |
| `module_name` | string | Yes |  |
| `app_type` | string | Yes |  |
| `connection_id` | string \| null | Yes |  |
| `connection_name` | string \| null | Yes | The name of the connection the action used, None for none |
| `is_read_action` | boolean | Yes | True for an action that only reads from the app (a viewer may run it); any other action can change data and needs an editor |
| `status` | string (validated \| succeeded \| failed \| outcome_unknown) | Yes | How a run ended |
| `data` | any | No | What the action answered, as the next step of a workflow would receive it; None unless it succeeded |
| `is_data_truncated` | boolean, default false | No | True when data was too large to answer: data is then the start of it as JSON text; narrow the action's filters to get it whole |
| `error_message` | string \| null | No | Why the action failed, or why its outcome is unknown |

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/modules/runs?region=usnv" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "module_id": "<module_id>",
  "module_version": "<module_version>"
}'
```

## Example response (200)

```json
{
  "module_id": "<module_id>",
  "module_version": "<module_version>",
  "module_name": "<module_name>",
  "app_type": "<app_type>",
  "connection_id": "<connection_id>",
  "connection_name": "<connection_name>",
  "is_read_action": false,
  "status": "validated",
  "data": "<data>",
  "is_data_truncated": false,
  "error_message": "<error_message>"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "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 connector apps](https://docs.stacksync.com/api-reference/connectors/list_connector_apps)
- [Get a connector app](https://docs.stacksync.com/api-reference/connectors/get_connector_app)
- [Get a connector module form](https://docs.stacksync.com/api-reference/connectors/get_connector_module_form)