# Update Workflow Step Output

Save a sample output for a step in the workflow's draft without running it, as Edit Step Output in the editor does. Later steps learn its fields and their tests read it, so you can build and test what comes after a step whose run has side effects. It replaces the saved sample. A Loop takes none of its own (LOOP_OUTPUT_FOLLOWS_SOURCE): its sample is the first record of the step it loops over, so set that step's. Saving it changes the draft's revision: use meta.revision on your next change.

`PUT https://connect.mindcloud.co/v2/workflows/:workflowId/steps/:stepId/output`

Permissions: `workflow:edit`.

## Parameters

### Path

- `workflowId` (string, required): The workflow's id, from List Workflows.
- `stepId` (string, required): The step's id, from List Workflow Steps or Get Workflow Definition.

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

- `output` (array, required): The sample records.
  The sample: an array of records, as the step would answer them.

## Example request

```bash
curl --request PUT \
  --url 'https://connect.mindcloud.co/v2/workflows/Wq3kZ8pLx2Nb/steps/SyDtUxIQeocK/output' \
  --header 'Authorization: Bearer $MINDCLOUD_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
  "output": [
    {
      "id": "8412",
      "email": "ada@example.com"
    }
  ]
}'
```

## Response fields

- `status` (string): succeeded or failed: how the run that saved the sample ended (a sample set by hand counts as succeeded). none: the step has no sample yet.
  Allowed values:
    - `succeeded`
    - `failed`
    - `none`
- `output` (object): The first records of the output (a JSON array as the step answered it), capped at 200 records and about 60 KB. Empty when there is no sample.
- `total` (number): How many records the output had in all. Null when there is no sample.
- `truncated` (boolean): True when output holds fewer records than total: the rest were left out of the sample, not lost. Later steps still learn their fields from the records kept.
- `truncatedBy` (string): Why output stopped short of total. Null unless truncated is true.
  Allowed values:
    - `records`: It reached the 200-record cap.
    - `size`: Its records reached about 60 KB first, so it keeps fewer than 200.
- `outputFields` (array of objects): The fields of the output records, learned from the sample and offered to later steps.
  - `key` (string): The field's path in each record: dotted, with [] marking an array (lines[].sku). Reference it as {{ steps.<stepId>.output[0].<key> }}.
  - `type` (string): Its type as seen in the sample: string, number, boolean, object, date, a type with [] for an array, or mixed.
- `error` (object): Why the run failed. Null unless status is failed.
  - `code` (string): The runtime's error code (ARGUMENTS_MISSING, 401_UNAUTHORIZED, DEFAULT, ...).
  - `message` (string): What the code means, for a person. What the app answered, if anything, is in output.
  - `status` (number): The HTTP status the app answered, when it answered one.
- `savedOn` (date): When the sample was saved. Null when there is none.
- `revision` (string): The draft's revision after the sample was saved (a sample is part of the step): send it in If-Match on your next change to the draft.
