n8n Masterclass IModule 2

2.1Webhook Triggers & API Orchestration

30 min 3 code blocks Practice Lab Homework Quiz (5Q)

Webhook Triggers: The Entry Point of Automation

Webhooks are the "nervous system" of the Automated Growth Empire. They allow external systems (like Shopify, Typeform, or a custom Python script) to trigger a workflow in n8n instantly. In this lesson, we learn how to architect a high-fidelity webhook receiver.

🏗️ The Webhook Lifecycle

  1. The Event: An action occurs in an external app (e.g., a new lead is submitted).
  2. The Payload: The external app sends a JSON POST request to your n8n URL.
  3. The Orchestration: n8n parses the JSON and triggers the subsequent nodes (Scoring, CRM Sync, Notification).
Technical Snippet

Technical Snippet: Testing Webhooks with ,[object Object]

Before connecting a real app, always test your webhook node manually:

bash
curl -X POST https://automate.yourdomain.com/webhook-test/unique-id \
     -H "Content-Type: application/json" \
     -d '{"email": "lead@example.com", "name": "Test Lead", "source": "LinkedIn"}'
Key Insight

Nuance: Production vs. Test URLs

n8n provides two types of webhook URLs.

  • Test URL: Only active when you are looking at the workflow in the browser. Used for development.
  • Production URL: Always active. You must Activate the workflow for this URL to respond.
Practice Lab

Practice Lab: The Lead Capture Loop

  1. Trigger: Add a Webhook node in n8n. Set the HTTP Method to POST.
  2. Action: Add a "Google Sheets" node. Connect it to a "Leads" sheet.
  3. Map: Use the "Expression" editor to map the email and name from the webhook to the sheet columns.
  4. Execute: Send a curl request and verify the lead appears in your sheet in real-time.

🇵🇰 Pakistan Use Case: The Karachi Restaurant Lead Funnel

Imagine you're building an automation for a Karachi digital agency that serves restaurant clients on Food Panda and Google Maps.

The Workflow:

  1. A customer fills a "Book a Table" form on your client's website
  2. The webhook fires to your n8n instance
  3. n8n adds the lead to a Google Sheet AND sends a WhatsApp notification to the restaurant owner via WATI API

Test Payload for a DHA Restaurant:

bash
curl -X POST https://automate.yourdomain.com/webhook/restaurant-leads \
     -H "Content-Type: application/json" \
     -d '{"name": "Ahmed Khan", "phone": "+923001234567", "party_size": 4, "restaurant": "Kolachi DHA", "source": "website"}'

This is exactly how agencies in Clifton and DHA automate their restaurant clients — zero manual work, instant owner notification.

Homework

Homework: The Multi-Source Receiver

Create a single webhook that handles leads from 3 different sources (LinkedIn, Meta, Website). Use an "If" node to route the lead to a different Slack channel based on the source field in the JSON payload.

Bonus Pakistan Challenge: Add a 4th source called "WhatsApp" that routes to a Google Sheet named "PK_Leads" — because in Pakistan, 70% of your real leads come through WhatsApp, not web forms.

📺 Recommended Videos & Resources

🎯 Mini-Challenge

Build your first webhook receiver: Create an n8n webhook endpoint, test it with a curl command, and have it log incoming data to a Google Sheet. Time yourself—can you do it in under 10 minutes?

🖼️ Visual Reference

code
📊 Webhook Event Flow (Multi-Source Lead Capture)

External Source (LinkedIn/Meta/Website/WhatsApp)
        │
        ├─→ New Lead Event
        │
        ↓
    ┌────────────────────┐
    │  n8n Webhook Node  │
    │  (Always Listening)│
    └────────┬───────────┘
             │
             ↓ Parse JSON
    ┌────────────────────┐
    │  IF Node (Router)  │
    │  Check: source = ? │
    └───┬───┬───┬────────┘
        │   │   │
   from from from from
 LinkedIn Meta Web WhatsApp
        │   │   │       │
        ↓   ↓   ↓       ↓
    Chan  Chan  Chan   Sheet
    #leads #ads #web  PK_Leads

Result: All leads flow in. Each source routes automatically.

Lesson Summary

Includes hands-on practice labHomework assignment included3 runnable code examples5-question knowledge check below

Quiz: Webhook Triggers

5 questions to test your understanding. Score 60% or higher to pass.