Advanced6 min
Code Export
Export your workflows as code. Run them in your own infrastructure or customize beyond the visual builder.
Overview
Why Export Code?
- Run workflows in your infrastructure
- Customize beyond visual builder
- Version control with git
- CI/CD integration
- Offline execution
Export Formats
- TypeScript - Full type safety
- JavaScript - Node.js compatible
- Python - For Python environments
- JSON - Portable definition
Exporting Workflows
From Dashboard
- Open your workflow
- Click Export > Export as Code
- Select format
- Download
Via API
GET /workflows/:id/export?format=typescript
Formats:
typescriptjavascriptpythonjson
TypeScript Export
Generated Code
// workflow-lead-notification.ts
import { Workflow, TriggerNode, ActionNode } from '@yourapp/workflow-runtime';
export const leadNotificationWorkflow = new Workflow({
id: 'wf_123',
name: 'Lead Notification',
description: 'Notify sales team on new leads',
});
// Trigger
const webhookTrigger = new TriggerNode({
type: 'webhook',
config: {
path: '/leads/new',
method: 'POST',
},
});
// Get lead data
const enrichLead = new ActionNode({
type: 'http',
config: {
url: 'https://api.clearbit.com/v2/people/find',
method: 'GET',
params: {
email: '{{trigger.email}}',
},
},
});
// Send Slack notification
const notifySlack = new ActionNode({
type: 'slack.send_message',
config: {
channel: '#sales-leads',
message: 'New lead: {{enrichLead.name}} from {{enrichLead.company}}',
},
});
// Define flow
leadNotificationWorkflow
.addTrigger(webhookTrigger)
.addNode(enrichLead)
.addNode(notifySlack)
.connect(webhookTrigger, enrichLead)
.connect(enrichLead, notifySlack);
export default leadNotificationWorkflow;
Running TypeScript
# Install runtime
npm install @yourapp/workflow-runtime
# Run workflow
npx ts-node workflow-lead-notification.ts
JavaScript Export
Generated Code
// workflow-lead-notification.js
const { Workflow, TriggerNode, ActionNode } = require('@yourapp/workflow-runtime');
const leadNotificationWorkflow = new Workflow({
id: 'wf_123',
name: 'Lead Notification',
});
// ... same structure as TypeScript
module.exports = leadNotificationWorkflow;
Running JavaScript
node workflow-lead-notification.js
Python Export
Generated Code
# workflow_lead_notification.py
from yourapp_runtime import Workflow, TriggerNode, ActionNode
lead_notification_workflow = Workflow(
id='wf_123',
name='Lead Notification',
description='Notify sales team on new leads',
)
# Trigger
webhook_trigger = TriggerNode(
type='webhook',
config={
'path': '/leads/new',
'method': 'POST',
},
)
# Get lead data
enrich_lead = ActionNode(
type='http',
config={
'url': 'https://api.clearbit.com/v2/people/find',
'method': 'GET',
'params': {
'email': '{{trigger.email}}',
},
},
)
# Send Slack notification
notify_slack = ActionNode(
type='slack.send_message',
config={
'channel': '#sales-leads',
'message': 'New lead: {{enrich_lead.name}}',
},
)
# Define flow
lead_notification_workflow \
.add_trigger(webhook_trigger) \
.add_node(enrich_lead) \
.add_node(notify_slack) \
.connect(webhook_trigger, enrich_lead) \
.connect(enrich_lead, notify_slack)
Running Python
pip install yourapp-runtime
python workflow_lead_notification.py
JSON Export
Structure
{
"version": "1.0",
"workflow": {
"id": "wf_123",
"name": "Lead Notification",
"description": "Notify sales team on new leads"
},
"nodes": [
{
"id": "node_1",
"type": "trigger.webhook",
"config": {
"path": "/leads/new",
"method": "POST"
}
},
{
"id": "node_2",
"type": "action.http",
"config": {...}
}
],
"edges": [
{
"source": "node_1",
"target": "node_2"
}
],
"variables": {
"SLACK_CHANNEL": "#sales-leads"
}
}
Using JSON
Import into other systems or convert to code.
Runtime Library
Installation
# Node.js
npm install @yourapp/workflow-runtime
# Python
pip install yourapp-runtime
Features
The runtime provides:
- Node execution engine
- Variable interpolation
- Error handling
- Logging
- Integration connectors
Configuration
import { Runtime } from '@yourapp/workflow-runtime';
const runtime = new Runtime({
credentials: {
slack: process.env.SLACK_TOKEN,
clearbit: process.env.CLEARBIT_KEY,
},
logging: {
level: 'debug',
output: 'console',
},
});
await runtime.execute(workflow, {
email: 'lead@example.com'
});
Customization
Adding Custom Logic
import { ActionNode } from '@yourapp/workflow-runtime';
// Custom action node
const customLogic = new ActionNode({
type: 'custom',
handler: async (input, context) => {
// Your custom code
const result = await myCustomFunction(input.data);
return { processed: result };
},
});
workflow.addNode(customLogic);
Extending Nodes
class CustomHTTPNode extends ActionNode {
async execute(input, context) {
// Add custom authentication
const headers = {
...input.headers,
'X-Custom-Auth': await getCustomAuth(),
};
return super.execute({ ...input, headers }, context);
}
}
Deployment Options
Serverless (AWS Lambda)
// handler.ts
import workflow from './workflow-lead-notification';
import { Runtime } from '@yourapp/workflow-runtime';
export const handler = async (event) => {
const runtime = new Runtime({...});
const result = await runtime.execute(workflow, JSON.parse(event.body));
return {
statusCode: 200,
body: JSON.stringify(result),
};
};
Docker
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "workflow-lead-notification.js"]
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: workflow-runner
spec:
replicas: 3
template:
spec:
containers:
- name: workflow
image: your-workflow:latest
env:
- name: SLACK_TOKEN
valueFrom:
secretKeyRef:
name: workflow-secrets
key: slack-token
Syncing Changes
Import Updated Code
POST /workflows/:id/import
Content-Type: application/json
{
"format": "typescript",
"code": "..."
}
Two-Way Sync
Keep visual builder and code in sync:
- Export code
- Make changes
- Import back
- Visual builder updates
Best Practices
1. Version Control
Store exported code in git.
2. Environment Variables
Use env vars for credentials:
const runtime = new Runtime({
credentials: {
slack: process.env.SLACK_TOKEN,
},
});
3. Testing
Write tests for custom logic:
describe('Lead Notification Workflow', () => {
it('should notify Slack on new lead', async () => {
const result = await runtime.execute(workflow, mockLead);
expect(result.slackSent).toBe(true);
});
});
4. Documentation
Comment your customizations.
Next Steps
- API Reference - API documentation
- Webhook API - Event webhooks
- Building MCPs - AI integrations
Tags
codeexportdevelopment