Zum Inhalt

Workflow: n8n Development

n8n Workflows bauen, debuggen und optimieren mit Claude Code.

Übersicht

Aspekt Details
Ziel Funktionierende n8n Workflows
Features Plan Mode, JSON-Generierung, Debugging
Scope Workflow-Design, Node-Konfiguration, Expressions
Output Importfähige Workflow-JSON

Feature-Kombination

┌─────────────────────────────────────────────────────────┐
│                   ANFORDERUNG                           │
│  "Ich brauche einen Workflow der X macht"               │
└───────────────────────────┬─────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│                    PLAN MODE                            │
│  Workflow-Struktur planen, Nodes identifizieren         │
└───────────────────────────┬─────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│              JSON GENERIERUNG                           │
│  Kompletten Workflow als importfähige JSON              │
└───────────────────────────┬─────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│              ITERATIVES DEBUGGING                       │
│  Fehler beheben, Expressions fixen, optimieren          │
└─────────────────────────────────────────────────────────┘

Workflow: Neuen Workflow erstellen

Schritt 1: Anforderung beschreiben

Erstelle einen n8n Workflow der:

1. Täglich um 8:00 Uhr läuft
2. FortiGate Firmware-Version via API abfragt
3. Mit bekannter Latest-Version vergleicht
4. Bei Abweichung Slack-Notification sendet

Output: Importfähige JSON

Schritt 2: Plan reviewen

Claude erstellt Workflow-Plan:

## Workflow: FortiGate Update Checker

### Nodes

1. **Schedule Trigger**
   - Typ: n8n-nodes-base.scheduleTrigger
   - Config: Täglich 8:00 Uhr

2. **HTTP Request - FortiGate API**
   - Typ: n8n-nodes-base.httpRequest
   - Method: GET
   - URL: https://{{host}}/api/v2/monitor/system/firmware
   - Auth: Bearer Token

3. **HTTP Request - Latest Version**
   - Typ: n8n-nodes-base.httpRequest
   - URL: FortiGuard Version API

4. **Compare Versions (Code Node)**
   - Typ: n8n-nodes-base.code
   - Vergleichslogik

5. **IF Node**
   - Bedingung: Update verfügbar?

6. **Slack Notification**
   - Typ: n8n-nodes-base.slack
   - Channel: #alerts

### Ablauf
Schedule → FortiGate API → Latest Version → Compare → IF → Slack

Schritt 3: JSON generieren lassen

Der Plan sieht gut aus. Generiere die komplette Workflow-JSON.

Schritt 4: Importieren und testen

  1. In n8n: Workflows → Import from File
  2. JSON einfügen
  3. Credentials zuweisen
  4. Testen

Workflow: Debugging

Schritt 1: Error beschreiben

Mein n8n Workflow hat diesen Fehler:

Node: HTTP Request
Error: "Cannot read properties of undefined (reading 'status')"

Hier der Node:
[Node JSON einfügen]

Hier die Input-Daten:
[Input JSON einfügen]

Schritt 2: Fix erhalten

Claude analysiert und schlägt Fix vor:

Das Problem: Der vorherige Node liefert manchmal kein 
Response-Objekt wenn die Anfrage fehlschlägt.

Fix im Code Node davor:
// Defensive Prüfung
const response = $input.first()?.json?.response;
if (!response) {
  return [{ json: { error: "No response", status: 0 } }];
}
return [{ json: response }];

Workflow: Expression-Hilfe

n8n Expressions können tricky sein. Claude hilft:

Ich brauche eine n8n Expression die:
- Datum von "2025-03-28T10:30:00Z" 
- Umwandelt in "28.03.2025 10:30"
- Für Timezone Europe/Berlin

Antwort:

{{ DateTime.fromISO($json.timestamp).setZone('Europe/Berlin').toFormat('dd.MM.yyyy HH:mm') }}

Beispiel-Workflows

Morning Briefing

{
  "name": "Morning Briefing",
  "nodes": [
    {
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "parameters": {
        "rule": {
          "interval": [{ "field": "cronExpression", "expression": "0 7 * * 1-5" }]
        }
      }
    },
    {
      "name": "Fetch News",
      "type": "n8n-nodes-base.httpRequest",
      "parameters": {
        "url": "https://newsapi.org/v2/top-headlines",
        "qs": {
          "category": "technology",
          "country": "de",
          "apiKey": "{{ $credentials.newsApiKey }}"
        }
      }
    },
    {
      "name": "Format with AI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "parameters": {
        "resource": "text",
        "operation": "message",
        "prompt": "Fasse diese News zusammen:\n{{ $json.articles.map(a => a.title).join('\\n') }}"
      }
    },
    {
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "parameters": {
        "toEmail": "team@example.com",
        "subject": "Morning Briefing {{ $now.format('dd.MM.yyyy') }}",
        "text": "={{ $json.text }}"
      }
    }
  ]
}

Alert Pipeline

Erstelle Workflow:
1. Webhook empfängt Alerts (JSON)
2. Deduplizierung (gleicher Alert in 5 min = ignorieren)
3. Severity-basiertes Routing:
   - Critical → PagerDuty + Slack
   - Warning → Slack only
   - Info → Log only
4. Alert-Historie in SQLite

Node-Typen Cheatsheet

Use Case Node Type Hinweise
API Calls httpRequest typeVersion: 4.2, Follow Redirects!
Scheduling scheduleTrigger Cron oder Interval
Code/Logic code JavaScript, $input, $json
Conditions if Expressions oder simple Rules
Loop splitInBatches Batch-Size beachten
AI/LLM @n8n/n8n-nodes-langchain.openAi Resource: text, Operation: message
Slack slack OAuth oder Webhook
Email emailSend SMTP Config
Files readWriteFile Für lokale Dateien

Tipps für gute Ergebnisse

DO ✅

Erstelle n8n Workflow:

Trigger: Webhook POST /api/backup-status
Input-Format: { "host": "...", "status": "success|failed", "size": 123 }

Logik:
- Failed → Slack Alert + Retry-Flag setzen
- Success → Update Tracking-Sheet

Output: Workflow JSON für n8n 2.13+
Credentials: Nutze Platzhalter die ich ersetzen kann

Konkretes Format, n8n Version, erwartete Credentials.


DON'T ❌

Mach nen Workflow für Backups

Trigger? Format? Actions? Notifications?


TIPP: Bestehenden Workflow erweitern 💡

Hier mein bestehender Workflow:
@workflows/backup-check.json

Erweitere um:
- Retry-Logik (3 Versuche, 5 min Pause)
- Error-Aggregation (sammle alle Fehler, eine Notification)

TIPP: Node-Dokumentation nutzen 💡

Wenn Claude einen falschen Node-Typ nutzt:

Der Node "execute Command" existiert in n8n 2.13 nicht mehr.
Hier die aktuelle Node-Liste: [Link]

Nutze den korrekten Node.

Kosten-Optimierung

Szenario Empfehlung
Einfacher Workflow (3-5 Nodes) Sonnet direkt
Komplexer Workflow (10+ Nodes) Plan Mode + Sonnet
Debugging Sonnet, iterativ
Workflow-Migration Sub-Agents für parallele Konvertierung

Troubleshooting

Node nicht erkannt

Fehler: "Node type not found: n8n-nodes-base.executeCommand"

Meine n8n Version: 2.13.4

Welcher Node ist der Ersatz?

Expression funktioniert nicht

Diese Expression wirft Error:
{{ $json.items.filter(i => i.active).length }}

Error: "filter is not a function"

$json.items sieht so aus:
[Beispiel-Daten]

Credential-Probleme

Workflow importiert, aber Credentials fehlen.

Diese Credential-Typen brauche ich:
- OpenAI API
- Slack OAuth

Welche Felder muss ich in n8n ausfüllen?

n8n + Claude Code Meta

Ironischerweise: Der Workflow der diese Doku aktualisiert wurde selbst mit dieser Methode erstellt. 🔄

Best Practices

Credentials niemals hardcoden

In n8n Workflows gibt es drei Credential-Ebenen:

// SCHLECHT: API Key im Code Node
const apiKey = "sk-ant-abc123...";  // Steht im Workflow-JSON!

// GUT: n8n Credentials System nutzen
// Im Code Node auf Credentials zugreifen:
const credentials = await this.getCredentials('anthropicApi');
const apiKey = credentials.apiKey;
Erstelle den Workflow mit Platzhaltern für Credentials:
- Credential-Namen: "FortiGate API", "Slack OAuth", "OpenAI"
- Keine Klartext-Secrets im Workflow-JSON
- Ich weise die Credentials nach dem Import zu

Error-Handling in Workflows

n8n hat kein automatisches Error-Handling – muss explizit eingebaut werden:

Füge Error-Handling hinzu:
1. IF-Node nach jedem HTTP-Request: Prüfe ob response.ok
2. Bei Fehler: Slack-Nachricht mit Details (Node, Error, Input)
3. Stop-on-Error vs Continue-on-Error bewusst wählen
4. Error-Workflow in n8n Settings konfigurieren

Beispiel-Pattern für HTTP Requests:

// Code Node nach HTTP Request
const response = $input.first().json;

if (!response || response.error) {
  throw new Error(`API Error: ${response?.error?.message || 'Unknown'}`);
}

// Weiterarbeiten mit validen Daten
return [{ json: response.result }];

Node-Versionen explizit angeben

n8n bricht manchmal die API zwischen Versionen:

Erstelle den Workflow für n8n Version 2.13+

Verwende:
- httpRequest typeVersion: 4.2
- code typeVersion: 2
- if typeVersion: 2

Wenn Claude falsche Versionen nutzt:

Der httpRequest Node hat in meiner Version (n8n 2.13.4)
diese Parameter-Struktur: [aktuellen Node-JSON zeigen]

Passe den generierten Workflow an.

Workflow-Dokumentation

Direkt in Claude generieren lassen:

Erstelle zusätzlich zur Workflow-JSON:
1. Beschreibung für den Workflow (Sticky Note Node am Anfang)
2. Kommentare für komplexe Code Nodes
3. README.md: Trigger, Input-Format, Output, Credentials-Setup

Sticky Note in n8n:

{
  "name": "Workflow Info",
  "type": "n8n-nodes-base.stickyNote",
  "parameters": {
    "content": "## FortiGate Update Checker\n\nPrüft täglich auf neue FortiOS Versionen.\n\n**Trigger:** Täglich 08:00\n**Credentials:** FortiGate API Token\n**Output:** Slack #alerts wenn Update verfügbar"
  }
}
Workflow: Claude Code Trainer Update
├── Schedule (daily)
├── HTTP Request (Anthropic Docs)
├── OpenAI (Zusammenfassung)
├── Code (Parse + Format)
└── Write File (docs/*.md)