n8n-workflow-sdk
Build n8n workflows programmatically with the official TypeScript SDK. Use when a user asks to create n8n workflows from code, generate workflow JSON, build automation pipelines programmatically, convert between n8n JSON and TypeScript, or integrate n8n workflow creation into applications.
What this skill does
# n8n Workflow SDK
## Overview
`@n8n/workflow-sdk` is the official TypeScript SDK from n8n (v0.2.0, released February 2026) for programmatically creating, validating, and converting workflows. Instead of dragging nodes in the UI, define workflows as code — type-safe, version-controlled, and composable. Supports all n8n node types including AI/LangChain nodes. Includes bidirectional conversion between JSON and TypeScript.
## Instructions
### Step 1: Install and Create a Basic Workflow
```bash
npm install @n8n/workflow-sdk
```
```typescript
// workflows/data-sync.ts — Programmatic workflow creation
import { WorkflowBuilder, manual, httpRequest, code } from '@n8n/workflow-sdk'
// Build a simple data sync workflow
const workflow = new WorkflowBuilder()
.withName('Daily Data Sync')
.addTrigger(manual())
.then(httpRequest({
url: 'https://api.example.com/users',
method: 'GET',
headers: {
Authorization: '={{ $env.API_KEY }}', // n8n expression for env variable
},
}))
.then(code({
language: 'typescript',
code: `
// Transform API response to internal format
return items.map(item => ({
json: {
id: item.json.id,
email: item.json.email,
name: \`\${item.json.firstName} \${item.json.lastName}\`,
active: item.json.status === 'active',
syncedAt: new Date().toISOString(),
}
}))
`,
}))
.build()
// workflow is now a valid n8n JSON object ready to import
console.log(JSON.stringify(workflow, null, 2))
```
### Step 2: Control Flow — Branching and Merging
```typescript
// workflows/lead-routing.ts — Conditional workflow with branches
import {
WorkflowBuilder, webhook, ifElse, merge,
httpRequest, node, sticky,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('Lead Routing')
// Trigger on incoming webhook
.addTrigger(webhook({
path: 'new-lead',
method: 'POST',
responseMode: 'onReceived',
}))
// Branch based on lead score
.then(ifElse({
conditions: {
combinator: 'and',
conditions: [
{ leftValue: '={{ $json.score }}', operator: 'gte', rightValue: 80 },
],
},
}))
// True branch — high-value lead → Salesforce + Slack notification
.onTrue(
httpRequest({
url: 'https://mycompany.salesforce.com/api/leads',
method: 'POST',
body: '={{ JSON.stringify($json) }}',
})
)
// False branch — low-score lead → add to nurture campaign
.onFalse(
httpRequest({
url: 'https://api.mailchimp.com/3.0/lists/abc123/members',
method: 'POST',
body: '={{ JSON.stringify({ email_address: $json.email, status: "subscribed" }) }}',
})
)
// Add documentation
.addSticky(sticky({
content: '## Lead Routing\nHigh-score leads (≥80) go to Salesforce.\nOthers enter nurture campaign.',
width: 300,
height: 150,
}))
.build()
```
### Step 3: AI/LangChain Workflows
```typescript
// workflows/ai-support-agent.ts — AI agent with tools and memory
import {
WorkflowBuilder, webhook,
languageModel, memory, tool, outputParser,
node,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('AI Support Agent')
.addTrigger(webhook({ path: 'support', method: 'POST' }))
// AI Agent node with LangChain components
.then(node('n8n-nodes-langchain.agent', {
text: '={{ $json.message }}',
systemMessage: `You are a helpful customer support agent for a SaaS product.
Use the available tools to look up account information and
knowledge base articles. Be concise and helpful.`,
}))
// Attach LLM
.withSub(languageModel('openAi', {
model: 'gpt-4o',
temperature: 0.3,
}))
// Attach conversation memory
.withSub(memory('windowBuffer', {
sessionKey: '={{ $json.userId }}',
windowSize: 20, // remember last 20 messages
}))
// Attach tools the agent can use
.withSub(tool('httpRequest', {
name: 'lookup_account',
description: 'Look up customer account by email or ID',
url: 'https://api.myapp.com/accounts/{{ $fromAi("query") }}',
method: 'GET',
}))
.withSub(tool('httpRequest', {
name: 'search_knowledge_base',
description: 'Search the knowledge base for help articles',
url: 'https://api.myapp.com/kb/search?q={{ $fromAi("query") }}',
method: 'GET',
}))
// Parse structured output
.then(outputParser('structured', {
schema: {
answer: { type: 'string', description: 'The response to the customer' },
category: { type: 'string', description: 'Issue category: billing, technical, general' },
escalate: { type: 'boolean', description: 'Whether to escalate to human agent' },
},
}))
.build()
```
### Step 4: Batch Processing with Split and Merge
```typescript
// workflows/bulk-enrichment.ts — Process records in batches
import {
WorkflowBuilder, schedule, httpRequest,
splitInBatches, merge, code, node,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('Contact Enrichment Pipeline')
// Run every night at 2 AM
.addTrigger(schedule({ rule: { interval: [{ field: 'hours', triggerAtHour: 2 }] } }))
// Fetch contacts that need enrichment
.then(httpRequest({
url: 'https://api.myapp.com/contacts?needs_enrichment=true&limit=500',
method: 'GET',
}))
// Process in batches of 50 to respect API rate limits
.then(splitInBatches({ batchSize: 50 }))
// Enrich each contact via Clearbit
.then(httpRequest({
url: 'https://person.clearbit.com/v2/people/find',
method: 'GET',
queryParameters: { email: '={{ $json.email }}' },
headers: { Authorization: '={{ $env.CLEARBIT_KEY }}' },
options: { batching: { batch: { batchSize: 10, batchInterval: 1000 } } },
}))
// Transform and save
.then(code({
language: 'typescript',
code: `
return items.map(item => ({
json: {
contactId: item.json.contactId,
company: item.json.company?.name,
title: item.json.title,
linkedIn: item.json.linkedin?.handle,
enrichedAt: new Date().toISOString(),
}
}))
`,
}))
.then(httpRequest({
url: 'https://api.myapp.com/contacts/bulk-update',
method: 'PATCH',
body: '={{ JSON.stringify($json) }}',
}))
.build()
```
### Step 5: Convert Between JSON and TypeScript
```typescript
// tools/convert.ts — Bidirectional workflow conversion
import {
generateWorkflowCode,
parseWorkflowCode,
validateWorkflow,
} from '@n8n/workflow-sdk'
// JSON → TypeScript (import existing workflows as code)
const existingWorkflowJson = require('./exported-workflow.json')
const tsCode = generateWorkflowCode(existingWorkflowJson)
console.log(tsCode)
// Outputs clean TypeScript using WorkflowBuilder API
// TypeScript → JSON (deploy code-defined workflows)
const workflowJson = parseWorkflowCode(tsCode)
console.log(JSON.stringify(workflowJson, null, 2))
// Outputs valid n8n JSON ready for import
// Validate before deploying
const errors = validateWorkflow(workflowJson)
if (errors.length > 0) {
console.error('Validation errors:', errors)
process.exit(1)
}
console.log('Workflow is valid ✓')
```
### Step 6: Deploy Workflows via n8n API
```typescript
// deploy.ts — Push SDK-built workflows to n8n instance
import { WorkflowBuilder } from '@n8n/workflow-sdk'
async function deployWorkflow(workflow: ReturnType<WorkflowBuilder['build']>) {
const response = await fetch(`${process.env.N8N_URL}/api/v1/workflows`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-N8N-API-KEY': process.env.N8N_API_KEY!,
},
body: JSON.stringify(workflow),
})
const result = await response.json()
console.log(`Deployed: ${result.name} (ID: ${result.id})`)
// Activate the workflow
await fetch(`${process.env.N8N_URL}/api/v1/workflows/${result.id}/activate`, {
method: 'PATCH',
headers: { 'X-N8N-API-KEY': process.env.N8N_API_KEY! },
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.