Write a workflow in code
Write workflows in the code editor using export default async function(ctx), configure execution tiers, and test with sample input.
Prerequisites: Your First Integration. Basic JavaScript familiarity.
Opening the code editor
Go to Integrations and open the Workflows tab.
Click Create workflow.
The workflow editor opens with three panels.
The three panels
The code editor consists of three panels which are as follows:
1. Configuration
Name
Required. Placeholder: "e.g. Sync Contacts".
Slug
Required on create. Unique identifier, used in the API path. Placeholder: "sync-contacts". Cannot be changed after creation.
Description
What the workflow does. Shown in the workflows table.
Execution tier
Instant (the default; synchronous, max 25s, or 2 minutes with the "Increase Instant timeout" entitlement), Standard (async, up to 15 minutes) or Long (async, up to 36 hours)
Execution timeout
Max time before the run is cut off. The slider is constrained to the tier: 1s to 25s for Instant (up to 2 min with the entitlement), 5s to 15min for Standard, 30s to 36h for Long.
Retry policy
Toggle on/off. When on, transient failures retry automatically, up to Max attempts (2-10, default 3).
2. Code editor
The editor shows <slug>.js with a default template:
Every workflow exports a default async function that receives ctx - the context object.
3. Tool tabs
On a new workflow there are three tabs:
Test - run the workflow with sample input
Connectors - the connectors the workflow calls
Contract - the input and output contract
Once the workflow is saved, more tabs appear (Diagram, Test cases, Executions, Sync reports, API and others). Diagram has a Docs view, but it documents this workflow, not the runtime; the runtime reference is in the code editor's autocomplete and in Workflow runtime API.
The Test tab has:
ctx.input - JSON input your workflow receives (Use contract fills it from the input contract)
ctx.headers - optional HTTP headers
A mode select: Live, Partial Mock or Fully Mock
A run button that follows the mode: Run Live, Run Partial Mock or Run Fully Mock. It executes the workflow without saving.
The ctx object
Your workflow receives a context object with:
input
The incoming data - request body from a webhook, event payload, or scheduler context
headers
HTTP headers from the incoming request (if triggered by webhook)
Writing a workflow
Example: Process incoming contacts
Example: Conditional logic
Testing
Click the Test tab in the right panel.
Enter sample JSON in ctx.input:
Optionally add headers in ctx.headers.
Pick a mode: Live (real calls to connected systems), Partial Mock (live where the connector has an active connection, a stored mock stub where it does not) or Fully Mock (stubs only).
Click the run button (Run Live, Run Partial Mock or Run Fully Mock).
The output appears below - check the result matches your expectations. Test runs are real when they run live: connectors are called and side effects happen.
Choosing an execution tier
Instant
Synchronous - caller waits for the result. Max 25 seconds (2 minutes with the "Increase Instant timeout" entitlement). Returns result inline.
API endpoints that need a response, quick lookups, simple transforms
Standard
Asynchronous - returns 202 immediately, executes in background. Up to 15 minutes.
Data syncs, multi-step processes, most workflows
Long
Asynchronous, for large data volumes and long-running processes. Up to 36 hours.
Batch imports, full data backfills, large report generation
The Workflows list has filter pills for All | Instant | Standard | Long so you can filter by tier.
Creating the workflow
Once your code works in testing:
Fill in Name, Slug and Description in the Configuration panel.
Select the appropriate Execution tier.
Set Execution timeout (for Instant, the slider tops out at 25s unless your organization has the extended Instant timeout).
Toggle Retry policy if you want automatic retries on failure.
Click Create Workflow (bottom of the Configuration panel).
The workflow appears in the Workflows list with status Unpublished. Until you publish it, every call returns WORKFLOW_NOT_PUBLISHED. Publish it from the Publish & Deploy section with Publish snapshot, then deploy it to an environment; see Lifecycle.
Editing an existing workflow
Go to Integrations and open the Workflows tab.
Click the workflow's row (or Edit in its
⋯menu).The code editor opens with the existing code.
Make your changes and test them. Draft edits auto-save (✓ Draft saved); Save workflow saves explicitly.
Publish again to make the change runnable. Note that publishing immediately changes what triggers routed to test (latest published) run.
What you've learned
The three-panel code editor layout (Configuration, Code, tool tabs)
The
ctxobject structure (input,headers)How to write workflow logic in JavaScript
How to test with sample data before creating
How to choose the right execution tier
How to create and edit workflows
Last updated
Was this helpful?

