# Save workflow draft step

> Add one step to the latest draft or replace it, with the edges to add and remove, as the builder's node Save does: the step's trigger is set up, then the draft is saved. A draft saved since you read it is refused with 409, never overwritten.

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

`PUT https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/{workflow_id}/draft/steps/{step_id}`

- Operation: `save_workflow_draft_step`
- 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. |
| `step_id` | string | Yes | The step, its workflow_module_instance_id in the workflow document. |

## 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 |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `step` | object (WorkflowSchemaModuleModel) | Yes | The step as the document holds it, added or replacing the stored one; its workflow_module_instance_id is the path's step_id |
| `step.name` | string | Yes |  |
| `step.workflow_module_instance_id` | string | Yes |  |
| `step.module_id` | string | Yes |  |
| `step.description` | string \| null | No |  |
| `step.properties` | object | Yes |  |
| `step.connections` | array of object (WorkflowModuleConnectionManagedModelByResourceId) \| object (WorkflowModuleConnectionManagedModelByName) \| object (WorkflowModuleConnectionUserDataModel), default [] | No |  |
| `step.module_options` | object (WorkflowSchemaModuleOptionsModel) \| null | No |  |
| `step.module_options.patches` | object \| null | No |  |
| `step.module_options.layout` | object (WorkflowSchemaModuleOptionsLayoutModel) \| null | No |  |
| `step.module_options.layout.group_module_instance_id` | string \| null | No |  |
| `step.module_options.enable_error_handling` | boolean \| null | No |  |
| `step.module_options.workflow_module_execution_timeout` | integer \| null | No |  |
| `step.error_handling_strategy` | object (WorkflowModuleErrorStrategyModel) \| null | No |  |
| `step.error_handling_strategy.conditions` | array of object (WorkflowModuleErrorStrategyConditionModel), default [] | No |  |
| `step.error_handling_strategy.conditions[].condition` | object (WorkflowModuleConditionGroupModel) \| object (WorkflowModuleConditionValueModel) \| object (WorkflowModuleConditionComparatorModel) | Yes |  |
| `step.error_handling_strategy.conditions[].retry_policy` | object (WorkflowModuleErrorStrategyConditionActionModel) | Yes |  |
| `step.error_handling_strategy.conditions[].retry_policy.retry_count` | integer, default 0 | No |  |
| `step.error_handling_strategy.conditions[].retry_policy.retry_interval` | integer, default 0 | No |  |
| `step.error_handling_strategy.else_condition` | object (WorkflowModuleErrorStrategyConditionActionModel) \| null | No |  |
| `step.error_handling_strategy.else_condition.retry_count` | integer, default 0 | No |  |
| `step.error_handling_strategy.else_condition.retry_interval` | integer, default 0 | No |  |
| `edges_to_add` | array of object (WorkflowSchemaEdgeModel) | No | Edges added to the draft; both ends are steps of the draft once this step is saved |
| `edges_to_add[].source` | object (WorkflowSchemaEdgeHandleModel) | Yes |  |
| `edges_to_add[].source.handle_id` | string \| null | No |  |
| `edges_to_add[].source.workflow_module_instance_id` | string | Yes |  |
| `edges_to_add[].target` | object (WorkflowSchemaEdgeHandleModel) | Yes |  |
| `edges_to_add[].target.handle_id` | string \| null | No |  |
| `edges_to_add[].target.workflow_module_instance_id` | string | Yes |  |
| `edges_to_add[].edge_id` | string | Yes |  |
| `edges_to_remove` | array of string | No | The edge_id of each edge removed from the draft |
| `expected_last_modified_time` | string (date-time) \| null | No | The last_modified_time of the draft you read; refused with 409 when it changed |
| `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 |
| --- | --- | --- | --- |
| `workflow_id` | string | Yes |  |
| `region` | string (besg \| usnv) | Yes |  |
| `version` | object (WorkflowVersionSummary) | Yes | A version without its document; step_ids lists its steps (workflow_module_instance_id) |
| `version.workflow_version` | string | Yes |  |
| `version.is_draft` | boolean | Yes |  |
| `version.is_deployed` | boolean | Yes |  |
| `version.last_modified_time` | string | Yes |  |
| `version.step_ids` | array of string | Yes |  |
| `triggers` | array of object (StepTrigger) | Yes |  |
| `triggers[].step_id` | string | Yes |  |
| `triggers[].status` | string (succeeded \| failed) | Yes | Whether what a step runs alongside the workflow (schedule, email route, Gmail watch, queue consumer...) is set up |
| `triggers[].msg` | string \| null | No |  |
| `step` | object (WorkflowSchemaModuleModel) | Yes |  |
| `step.name` | string | Yes |  |
| `step.workflow_module_instance_id` | string | Yes |  |
| `step.module_id` | string | Yes |  |
| `step.description` | string \| null | No |  |
| `step.properties` | object | Yes |  |
| `step.connections` | array of object (WorkflowModuleConnectionManagedModelByResourceId) \| object (WorkflowModuleConnectionManagedModelByName) \| object (WorkflowModuleConnectionUserDataModel), default [] | No |  |
| `step.module_options` | object (WorkflowSchemaModuleOptionsModel) \| null | No |  |
| `step.module_options.patches` | object \| null | No |  |
| `step.module_options.layout` | object (WorkflowSchemaModuleOptionsLayoutModel) \| null | No |  |
| `step.module_options.layout.group_module_instance_id` | string \| null | No |  |
| `step.module_options.enable_error_handling` | boolean \| null | No |  |
| `step.module_options.workflow_module_execution_timeout` | integer \| null | No |  |
| `step.error_handling_strategy` | object (WorkflowModuleErrorStrategyModel) \| null | No |  |
| `step.error_handling_strategy.conditions` | array of object (WorkflowModuleErrorStrategyConditionModel), default [] | No |  |
| `step.error_handling_strategy.conditions[].condition` | object (WorkflowModuleConditionGroupModel) \| object (WorkflowModuleConditionValueModel) \| object (WorkflowModuleConditionComparatorModel) | Yes |  |
| `step.error_handling_strategy.conditions[].retry_policy` | object (WorkflowModuleErrorStrategyConditionActionModel) | Yes |  |
| `step.error_handling_strategy.conditions[].retry_policy.retry_count` | integer, default 0 | No |  |
| `step.error_handling_strategy.conditions[].retry_policy.retry_interval` | integer, default 0 | No |  |
| `step.error_handling_strategy.else_condition` | object (WorkflowModuleErrorStrategyConditionActionModel) \| null | No |  |
| `step.error_handling_strategy.else_condition.retry_count` | integer, default 0 | No |  |
| `step.error_handling_strategy.else_condition.retry_interval` | integer, default 0 | No |  |
| `edges` | array of object (WorkflowSchemaEdgeModel) | Yes |  |
| `edges[].source` | object (WorkflowSchemaEdgeHandleModel) | Yes |  |
| `edges[].source.handle_id` | string \| null | No |  |
| `edges[].source.workflow_module_instance_id` | string | Yes |  |
| `edges[].target` | object (WorkflowSchemaEdgeHandleModel) | Yes |  |
| `edges[].target.handle_id` | string \| null | No |  |
| `edges[].target.workflow_module_instance_id` | string | Yes |  |
| `edges[].edge_id` | string | Yes |  |
| `webhook_trigger` | object (WebhookTrigger) \| null | No | For a webhook trigger step: the URLs that run it |
| `webhook_trigger.step_id` | string | Yes |  |
| `webhook_trigger.draft` | object (WebhookTriggerRequest) \| null | Yes | Runs the latest draft; null when the latest version is not a draft holding the step |
| `webhook_trigger.draft.url` | string | Yes | Queues a run of this version and answers its id |
| `webhook_trigger.draft.method` | string | Yes | The HTTP method the step takes: GET or POST |
| `webhook_trigger.draft.wait_for_result_url` | string \| null | Yes | When the step waits for the result: the URL answering the run's result instead of its id; null otherwise |
| `webhook_trigger.draft.requires_api_key` | boolean | Yes | Send one of the step's API keys as `Authorization: Bearer <key>`; a key is shown once, when it is generated on the step in the web app |
| `webhook_trigger.draft.query_parameter_names` | array of string | Yes | The query parameters the step reads |
| `webhook_trigger.draft.header_names` | array of string | Yes | The headers the step reads |
| `webhook_trigger.deployed` | object (WebhookTriggerRequest) \| null | Yes | Runs the deployed version; null when no deployed version holds the step |
| `webhook_trigger.deployed.url` | string | Yes | Queues a run of this version and answers its id |
| `webhook_trigger.deployed.method` | string | Yes | The HTTP method the step takes: GET or POST |
| `webhook_trigger.deployed.wait_for_result_url` | string \| null | Yes | When the step waits for the result: the URL answering the run's result instead of its id; null otherwise |
| `webhook_trigger.deployed.requires_api_key` | boolean | Yes | Send one of the step's API keys as `Authorization: Bearer <key>`; a key is shown once, when it is generated on the step in the web app |
| `webhook_trigger.deployed.query_parameter_names` | array of string | Yes | The query parameters the step reads |
| `webhook_trigger.deployed.header_names` | array of string | Yes | The headers the step reads |

### 204 No Content

No body.

## Example request

```bash
curl -X PUT "https://api.stacksync.com/v1/workspaces/{workspace_id}/workflows/{workflow_id}/draft/steps/{step_id}?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "edges_to_add": [
    {
      "edge_id": "input-wait_5_seconds",
      "source": {
        "workflow_module_instance_id": "input"
      },
      "target": {
        "workflow_module_instance_id": "wait_5_seconds"
      }
    }
  ],
  "step": {
    "module_id": "system-wait-1",
    "name": "Wait 5 seconds",
    "properties": {
      "wait_for": 5
    },
    "workflow_module_instance_id": "wait_5_seconds"
  }
}'
```

## Example response (200)

```json
{
  "workflow_id": "<workflow_id>",
  "region": "besg",
  "version": {
    "workflow_version": "<workflow_version>",
    "is_draft": false,
    "is_deployed": false,
    "last_modified_time": "<last_modified_time>",
    "step_ids": [
      "<step_ids>"
    ]
  },
  "triggers": [
    {
      "step_id": "<step_id>",
      "status": "succeeded",
      "msg": "<msg>"
    }
  ],
  "step": {
    "name": "<name>",
    "workflow_module_instance_id": "<workflow_module_instance_id>",
    "module_id": "<module_id>",
    "description": "<description>",
    "properties": {},
    "connections": [],
    "module_options": {
      "patches": {},
      "layout": {
        "group_module_instance_id": "<group_module_instance_id>"
      },
      "enable_error_handling": false,
      "workflow_module_execution_timeout": 0
    },
    "error_handling_strategy": {
      "conditions": [],
      "else_condition": {
        "retry_count": 0,
        "retry_interval": 0
      }
    }
  },
  "edges": [
    {
      "source": {
        "handle_id": "<handle_id>",
        "workflow_module_instance_id": "<workflow_module_instance_id>"
      },
      "target": {
        "handle_id": "<handle_id>",
        "workflow_module_instance_id": "<workflow_module_instance_id>"
      },
      "edge_id": "<edge_id>"
    }
  ],
  "webhook_trigger": {
    "step_id": "<step_id>",
    "draft": {
      "url": "<url>",
      "method": "<method>",
      "wait_for_result_url": "<wait_for_result_url>",
      "requires_api_key": false,
      "query_parameter_names": [
        "<query_parameter_names>"
      ],
      "header_names": [
        "<header_names>"
      ]
    },
    "deployed": {
      "url": "<url>",
      "method": "<method>",
      "wait_for_result_url": "<wait_for_result_url>",
      "requires_api_key": false,
      "query_parameter_names": [
        "<query_parameter_names>"
      ],
      "header_names": [
        "<header_names>"
      ]
    }
  }
}
```

## 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 }` |

## 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)
- [Delete workflow draft step](https://docs.stacksync.com/api-reference/workflows/delete_workflow_draft_step)
- [Run workflow](https://docs.stacksync.com/api-reference/workflows/run_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)