---
title: Build a Workflow
description: Create a workflow, add a trigger and steps, set them up, test, publish and run it, all through the API.
---

Every endpoint below links to its reference page, which lists each field it takes and answers. The values a step reads from earlier in the run are on [Workflow References](/docs/api/rest/introduction/workflow-references).

## How changes are saved

A workflow has a draft, which you change, and published versions, which run. Every change below goes to the draft, so nothing runs until you publish.

Each change to the draft takes the draft's revision in the `If-Match` header and answers the new one in `meta.revision`. Send the revision you read last. When someone else changed the draft first, the change is refused with `412` and `error.details.revision` holds the current revision: read the draft again, then retry. Read the first revision from [Get Workflow Definition](/docs/api/rest/actions/get-workflow-definition).

## Build it in one call

After creating the workflow, the fastest way to build it, and the one to use from an agent, is [Set Workflow Definition](/docs/api/rest/actions/set-workflow-definition): send every trigger and step at once, nested as they run, each with its configuration. Give each new step a `ref` of your own and reference it by that ref anywhere in the same body, such as `{{ steps.users.output[0].id }}`; the answer maps each ref to the id it got. Everything is applied in one change, all or nothing, and every problem comes back at once with its JSON Pointer into your body. To change the workflow later, read it with [Get Workflow Definition](/docs/api/rest/actions/get-workflow-definition), edit what you read and send it back: a step you leave out is removed. Check a body first, without saving it, with [Validate Workflow Definition](/docs/api/rest/actions/validate-workflow-definition).

One thing takes a second call: a Map step's code reads each input by a key that ends in the last four characters of that step's id, in capitals, such as `input['slackListUsers7K2Q']`, and a step created in the same call has no id until the call answers. Add the Map step with its inputs and no code in the definition (it is saved, and shows as not set up yet), then set code that reads a new step with [Update Workflow Step Configuration](/docs/api/rest/actions/update-workflow-step-configuration), using the key the answer gives in `inputKeys`.

The sections below build the same workflow one call at a time, which suits small edits and shows what each part takes.

## 1. Create the workflow

[Create Workflow](/docs/api/rest/actions/create-workflow) makes an empty, disabled workflow. Send `"type": "function"` for one other workflows call.

## 2. Add a trigger

[Add Workflow Trigger](/docs/api/rest/actions/add-workflow-trigger) takes `schedule`, `webhook`, `runWorkflow` or an app slug. A webhook trigger's address is in its configuration: read it with [Get Workflow Trigger Configuration](/docs/api/rest/actions/get-workflow-trigger-configuration). Set a schedule or an app event with [Update Workflow Trigger Configuration](/docs/api/rest/actions/update-workflow-trigger-configuration). To capture a sample call to a webhook, use [Listen Workflow Trigger](/docs/api/rest/actions/listen-workflow-trigger).

## 3. Add steps

Find the app and action with [List Universal Apps](/docs/api/rest/actions/list-universal-apps) (`includeBuiltins=true` adds If/Else, Loop, Map and the other built-in steps, which [Built-in Steps](/docs/api/rest/introduction/built-in-steps) describes) and [List Universal Actions](/docs/api/rest/actions/list-universal-actions). Then add the step with [Add Workflow Step](/docs/api/rest/actions/add-workflow-step). Its `position` puts it inside a loop or an If/Else lane; the slots are on [Workflow References](/docs/api/rest/introduction/workflow-references). Move steps later with [Set Workflow Step Order](/docs/api/rest/actions/set-workflow-step-order).

## 4. Set each step up

[Get Workflow Step Schema](/docs/api/rest/actions/get-workflow-step-schema) lists what a step takes: its arguments, options, the connection it needs and the output fields later steps can read. Set them with [Update Workflow Step Configuration](/docs/api/rest/actions/update-workflow-step-configuration); its reference page shows the connection object. To check values first without saving them, send the same body to [Validate Workflow Step Configuration](/docs/api/rest/actions/validate-workflow-step-configuration). Choose from an app's own lists with [Run Workflow Step Lookup](/docs/api/rest/actions/run-workflow-step-lookup). An app step that lists records reads only its first page, at the action's default page size (Get Workflow Step Schema's `size.default`), unless you set its `pagination` option: `"mode": "all"` reads every page, except on an action that pages by size only, which takes `"mode": "single"` with a larger `size` (Get Workflow Step Schema lists the modes an action takes). Paging, building a list argument from earlier records, and condition rules are on [Workflow References](/docs/api/rest/introduction/workflow-references).

## 5. Test

[Test Workflow Step](/docs/api/rest/actions/test-workflow-step) runs one step for real, with its saved connection: a step that creates a record creates it. Its output becomes the sample later steps read. To save a sample without running the step, use [Update Workflow Step Output](/docs/api/rest/actions/update-workflow-step-output). A Loop is not tested on its own and takes no sample of its own: give the step it loops over a sample, and the Loop's sample is that sample's first record. A sample keeps at most a fixed number of records; `truncated` says when the rest were left out.

## 6. Publish and turn it on

[Validate Workflow](/docs/api/rest/actions/validate-workflow) lists what would block publishing. [Publish Workflow](/docs/api/rest/actions/publish-workflow) makes the draft the version that runs. Then turn the workflow on with `"isActive": true` in [Update Workflow](/docs/api/rest/actions/update-workflow).

## 7. Run it

Call the trigger, or start a run with [Run Workflow](/docs/api/rest/actions/run-workflow) and follow it with [Get Run](/docs/api/rest/actions/get-run). [List Run Steps](/docs/api/rest/actions/list-run-steps) and [Get a Run Step](/docs/api/rest/actions/get-run-step) show what each step received and returned.
