2026-06-07

n8n API & SDK: Programmatic Workflow Management for Developers

Master the n8n REST API and Node.js SDK. Create, deploy, execute, and manage workflows programmatically. CI/CD pipeline integration, workflow-as-code patterns, bulk operations, and automation testing with the n8n API.

n8n API & SDK: Programmatic Workflow Management for Developers

The n8n editor is great for building workflows. But when you're managing dozens (or hundreds) of workflows across multiple environments, you need programmatic control. The n8n REST API and Node.js SDK let you treat workflows like code — version-controlled, CI/CD-deployed, and testable.

The n8n REST API

Every n8n instance exposes a REST API on the same port (default 5678). You need an API key to use it.

Getting an API Key

In n8n UI: Settings → n8n API → Create API Key

Or via environment variable:

```yaml environment:

  • N8N_API_KEY=your-generated-api-key ```

Core Endpoints

```bash

List all workflows

curl -H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows

Get a specific workflow

curl -H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows/WORKFLOW_ID

Create a workflow from JSON

curl -X POST
-H "Content-Type: application/json"
-H "X-N8N-API-KEY: $N8N_API_KEY"
-d @workflow.json
https://n8n.yourdomain.com/api/v1/workflows

Execute a workflow

curl -X POST
-H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows/WORKFLOW_ID/execute

Activate/Deactivate

curl -X PATCH
-H "X-N8N-API-KEY: $N8N_API_KEY"
-d '{"active": true}'
https://n8n.yourdomain.com/api/v1/workflows/WORKFLOW_ID

Delete a workflow

curl -X DELETE
-H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows/WORKFLOW_ID ```

Pattern #1: CI/CD for Workflows

Store workflow JSONs in Git and deploy via CI/CD:

```yaml

.github/workflows/deploy-n8n.yml

name: Deploy n8n Workflows on: push: paths: - 'workflows/**/*.json' branches: [main]

jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Deploy workflows run: | for f in workflows/*.json; do curl -X POST
-H "Content-Type: application/json"
-H "X-N8N-API-KEY: ${{ secrets.N8N_API_KEY }}"
-d "@$f"
https://n8n.${{ secrets.N8N_HOST }}/api/v1/workflows echo "Deployed: $f" done ```

Now every push to main deploys your workflows. No manual importing. No "which version is running in production?" confusion.

Pattern #2: Workflow-as-Code with TypeScript

Define workflows in TypeScript for type safety and reusability:

```typescript // Define the workflow structure interface WorkflowNode { id: string; name: string; type: string; position: [number, number]; parameters: Record<string, unknown>; }

function createSlackNotificationWorkflow(webhookUrl: string): object { return { name: "Slack Notifier", nodes: [ { id: "webhook-1", name: "Webhook", type: "n8n-nodes-base.webhook", position: [250, 300], parameters: { httpMethod: "POST", path: "notify" } }, { id: "slack-1", name: "Slack", type: "n8n-nodes-base.slack", position: [450, 300], parameters: { webhookUrl } } ], connections: { "Webhook": { main: [[{ node: "Slack", type: "main", index: 0 }]] } } }; } ```

Deploy with the API:

```typescript const workflow = createSlackNotificationWorkflow(process.env.SLACK_WEBHOOK!);

await fetch(https://n8n.yourdomain.com/api/v1/workflows, { method: "POST", headers: { "Content-Type": "application/json", "X-N8N-API-KEY": process.env.N8N_API_KEY!, }, body: JSON.stringify(workflow), }); ```

Pattern #3: Bulk Operations

Activate all workflows tagged "production":

```bash curl -H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows?tags=production | jq -r '.data[].id' | while read id; do curl -X PATCH
-H "X-N8N-API-KEY: $N8N_API_KEY"
-d '{"active": true}'
"https://n8n.yourdomain.com/api/v1/workflows/$id" echo "Activated: $id" done ```

Pattern #4: Health Check Monitoring

Ping your critical workflows and alert if they haven't run:

```bash #!/bin/bash

Check if Stripe invoice workflow ran in the last 2 hours

LAST_RUN=$(curl -s
-H "X-N8N-API-KEY: $N8N_API_KEY"
https://n8n.yourdomain.com/api/v1/workflows/INVOICE_WF_ID | jq -r '.updatedAt')

Compare timestamps, alert if stale...

```

API Rate Limits

n8n's API doesn't have hard rate limits, but be reasonable:

  • Don't poll more than once per minute per workflow
  • Batch operations: 100 workflows per minute is safe
  • Avoid concurrent modifications to the same workflow

When to Use the API vs the Editor

  • Editor: Building, debugging, one-off testing
  • API: CI/CD deployment, bulk operations, monitoring, integrations with other tools

A mature n8n setup uses both: build in the editor, export to JSON, deploy via API from Git.

Start automating your automation platform. All FlowForge templates export as clean JSON ready for API deployment.

Related n8n Templates

These pre-built n8n templates complement what you just read. Import and run in minutes.

Related Articles

More in-depth guides and comparisons to level up your n8n skills.

Ready to automate?

Browse 25+ production-ready n8n templates. Import, configure, and run — all in under 10 minutes.

Browse Templates