# n8n Integration
<!--
ref: @integrations/n8n-integration
tags: [n8n, automation, Claude API, integration, protocol execution]
triggers: [new customer inquiry, event received via webhook, scheduled task, command execution]
trigger_prompt: When an event occurs that requires protocol execution, such as a new customer inquiry or a scheduled task, this integration activates to automate the response process.
category: integration
last_reviewed: 2026-04-30
complements: [@integrations/n8n-mvp-prototyping, @protocol/chunk]
audience: [agent-author, terminal-only]
version: 5
updated_at: 2026-07-14T20:44:24.604Z
-->

Integrate n8n with Claude API to automate workflows and execute protocols seamlessly.

### Integration Patterns

**1. HTTP Request + Claude API**
- n8n triggers on schedule/event
- Calls Claude API with protocol in system prompt
- Parses response for structured data
- Routes based on protocol output

**2. Execute Command Node**
```javascript
// n8n Function node
const protocol = 'stepping';
const task = $input.item.json.task;

// Call protocol CLI
const command = `protocol fetch ${protocol}`;
// Execute and pass to Claude
```

**3. Custom n8n Node** (Advanced)
Create protocol-executor node that:
- Selects protocol by name or tag
- Loads from local protocol directory
- Executes via Claude API
- Returns structured output

**4. Webhook Trigger**
- n8n webhook receives event
- Maps event to protocol + parameters
- Executes protocol via Claude API
- Returns result to caller or routes internally

### Example Workflow: Business Process Automation

```
Trigger: New customer inquiry (webhook)
↓
[HTTP Request] Fetch customer context
↓
[Function] Load inquiry-handler protocol
↓
[HTTP Request] Execute protocol via Claude API
↓
[IF] Check confidence level
├─ High → [Send Response]
└─ Low → [Notify Human] + [Wait for Approval]
```

### Protocol Response Format for n8n

Protocols executed via n8n should return JSON:
```json
{
  "status": "success|needs_approval|error",
  "confidence": 0.85,
  "result": {
    "action": "send_email",
    "parameters": {...}
  },
  "reasoning": "Brief explanation",
  "escalate": false
}
```

### Best Practices
- Keep protocols stateless when possible
- Pass context via webhook/API payload
- Use n8n variables for secrets/credentials
- Log executions via work session storage (files, S3, API, etc.)
- Set timeouts for long-running protocols
- Handle errors gracefully with fallbacks

## n8n Starter Template

```json
{
  "name": "Protocol Executor",
  "nodes": [
    {
      "name": "Trigger",
      "type": "n8n-nodes-base.webhook"
    },
    {
      "name": "Load Protocol",
      "type": "n8n-nodes-base.function",
      "parameters": {
        "code": "const fs = require('fs');\nconst protocol = $input.item.json.protocol;\nconst content = fs.readFileSync(`/path/to/protocol/${protocol}.md`, 'utf8');\nreturn { protocol: content };"
      }
    },
    {
      "name": "Execute via Claude",
      "type": "n8n-nodes-base.httpRequest",
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "method": "POST",
        "authentication": "headerAuth",
        "body": {
          "model": "claude-sonnet-4",
          "system": "{{$node['Load Protocol'].json.protocol}}",
          "messages": [
            {"role": "user", "content": "{{$json.task}}"}
          ]
        }
      }
    },
    {
      "name": "Parse Response",
      "type": "n8n-nodes-base.function"
    }
  ]
}
```

*See also: [@integrations/n8n-mvp-prototyping](/@integrations/n8n-mvp-prototyping.md) — when to use n8n vs agentic automation.*

---

*Related: `@integrations/linkedin` · `@integrations/agent-browser` · `@protocol/protocol-api` · `@content/youtube/steph-france/turn-all-your-meetings-into-viral-content` · `@content/youtube/dan-martell/it-s-actually-pretty-easy-to-get-ahead-of-99-of-people-with-ai`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*