top of page

LBSocial

n8n Webhook Tutorial: Automate YouTube Data Extraction with OpenClaw AI

This tutorial outlines the technical process for integrating an OpenClaw AI agent into an n8n automation workflow using a Webhook. The objective is to build a secure automation pipeline that extracts, cleans, and summarizes YouTube video metadata, triggered directly via a Telegram interface.


OpenClaw + n8n Webhook Tutorial: Collect YouTube Metadata with an AI Agent

System Architecture Overview


Before diving into the implementation details, it is essential to understand the underlying infrastructure. The following diagram illustrates the high-level interaction between the user interface, the AI reasoning layer, and the automation execution engine.


Flowchart titled "Today's Architecture" shows data process from Telegram to YouTube via OpenClaw, n8n, YouTube Data API. Includes text and diagrams.
 The high-level interaction between the user interface, the AI reasoning layer, and the automation execution engine

The architecture follows a decoupled pattern where Telegram serves as the user interface, transmitting requests to OpenClaw, the AI reasoning agent. OpenClaw then invokes a specific skill that triggers an n8n Webhook hosted on the same Google Cloud VM. This separation ensures that the YouTube Data API credentials remain securely managed within n8n, while the AI agent focuses solely on intent recognition and result summarization.



The Role of Webhooks in AI Automation


A primary justification for this architecture is security and system modularity. By utilizing n8n as a middleware layer, private API keys are abstracted away from the AI agent. The OpenClaw agent communicates with n8n via a standard POST request, enabling n8n to securely handle complex data transformations and external API calls.


Interactive Demonstration: The Webhook Request-Response Cycle


To conceptualize how n8n functions as an HTTP Server—holding the connection open and returning data synchronously—interact with the network visualization below:




Phase 1: Constructing the Core n8n Data Workflow


The construction begins by establishing a verified baseline using manual input nodes to validate the YouTube API connection before introducing the webhook trigger.


Prerequisite: Obtaining a YouTube Data API Key


To interface with YouTube, a valid API Key is required from the Google Cloud Console.


  1. Project Selection: An existing Google Cloud project can be utilized; creating a new project specifically for this task is unnecessary.

  2. Enable API: Navigate to the "APIs & Services" library and enable the YouTube Data API v3.

  3. Generate Credentials: Create a new API Key under the "Credentials" tab.

  4. Security Best Practice: It is highly recommended to apply "API restrictions" to the key, limiting its use to the YouTube Data API v3 only.


Step 1.1: Simulate Manual Input (Set Node)


Initialize the workflow with a Set node. Add a String field named youtube_url and input a test URL (e.g., https://www.youtube.com/watch?v=AN2WL_jBoY8&t=3s).


Step 1.2: Extract the Video ID (Code Node)


A JavaScript snippet is implemented to reliably parse the exact 11-character Video ID from various YouTube URL formats:


const input = $json.body || $json;
const value = input.youtube_url || input.video_url || input.url || input.video_id || "";

if (!value) {
  throw new Error("Missing youtube_url, video_url, url, or video_id");
}

let videoId = value;
const patterns = [
  /v=([0-9A-Za-z_-]{11})/,
  /youtu\.be\/([0-9A-Za-z_-]{11})/,
  /shorts\/([0-9A-Za-z_-]{11})/
];

for (const pattern of patterns) {
  const match = value.match(pattern);
  if (match) {
    videoId = match[1];
    break;
  }
}

return [{ json: { video_id: videoId } }];

Step 1.3: Request YouTube Metadata (HTTP Request Node)


Configure a GET request directed to the official Google API endpoint. This node acts as the bridge between your workflow and YouTube's database.



Step 1.4: Data Sanitization (Code Node)


To optimize token consumption, the extensive JSON payload is sanitized to extract only essential fields and parse hashtags into graph-ready topics.


const item = $json.items?.[0];
if (!item) return [{ json: { ok: false, error: "Video not found" } }];

const snippet = item.snippet || {};
const statistics = item.statistics || {};
const description = snippet.description || "";

// Extract hashtags and convert them to topics
const hashtags = description.match(/#[\p{L}\p{N}_-]+/gu) || [];
const topics = hashtags.map(tag => tag.replace(/^#/, ""));

return [{
  json: {
    ok: true,
    video_id: item.id,
    title: snippet.title || "",
    channel_title: snippet.channelTitle || "",
    statistics: {
      view_count: statistics.viewCount || "0",
      like_count: statistics.likeCount || "0"
    },
    topics: topics,
    collected_at: new Date().toISOString()
  }
}];



Phase 2: Integrating the Webhook & Synchronous Response


The workflow is finalized by replacing manual inputs with a Webhook trigger and a synchronous response node.


Step 2.1: Configure the Webhook Node


  • HTTP Method: POST

  • Path: youtube-metadata-demo

  • Respond: Select Using "Respond to Webhook" Node. This ensures the HTTP connection remains open until the workflow completes.


Step 2.2: Terminal Connectivity Verification (Test URL)


Execute the following curl command in a terminal to transmit test data to the n8n test endpoint:


curl -sS -X POST "http://localhost:5678/webhook-test/youtube-metadata-demo" \
  -H "Content-Type: application/json" \
  -d '{"youtube_url":"https://www.youtube.com/watch?v=AN2WL_jBoY8&t=3s"}' | jq

Step 2.3: Configure the "Respond to Webhook" Node


Append a Respond to Webhook node at the terminus of the workflow. This node is critical for synchronous communication.


  • Respond With: Select JSON

  • Response Body: You must switch this field to Expression mode (click the toggle/gear icon next to the field). Then, clear the default text and input {{ $json }}.

  • This configuration ensures n8n dynamically parses the output and returns the sanitized JSON object to the originating client through the established HTTP connection.


Workflow diagram with nodes: Webhook, Get video id, Request meta, Clean data, Respond to Webhook. Browser tabs and "Execute workflow" button visible.
Full 5-node workflow

Step 2.4: Production Execution


After publishing the workflow, verify the production endpoint:


curl -sS -X POST "http://localhost:5678/webhook/youtube-metadata-demo" \
  -H "Content-Type: application/json" \
  -d '{"youtube_url":"https://www.youtube.com/watch?v=AN2WL_jBoY8&t=3s"}' | jq


Phase 3: Generating the OpenClaw Skill


Finally, configure the OpenClaw agent to interface with the n8n webhook. Within the Telegram interface, submit the following specification to the Skill Creator:


Create a new OpenClaw skill named n8n-youtube-metadata.

Purpose:
This skill should be used when the user asks OpenClaw to collect, fetch, inspect, or summarize metadata for a YouTube video.

Behavior:
The skill should call the local n8n production webhook through this command:
curl -sS -X POST "http://localhost:5678/webhook/youtube-metadata-demo" \
  -H "Content-Type: application/json" \
  -d '{"youtube_url":"YOUTUBE_URL"}'

Important:
- This skill only collects official YouTube metadata.
- The YouTube API key is stored in n8n credentials, not in OpenClaw.
- OpenClaw should summarize the returned JSON.

Response style:
After calling the webhook, summarize: Title, Channel, Published date, Duration, Statistics, and Topics. Mention that it is ready for embedding and Neo4j GraphRAG ingestion.

How to Use the Skill in Telegram


Once the skill is generated, simply send a YouTube URL to your Agent with a natural language prompt:

"Use the n8n-youtube-metadata skill to fetch fresh metadata for this video: https://youtu.be/AN2WL_jBoY8"

n8n interface showing multiple workflow executions labeled "youtube-metadata-demo" with success status. A Telegram bot displays video details and a link.
OpenClaw summary response in Telegram

Conclusion: Wrapping Up Our n8n Webhook Tutorial


In this tutorial, we demonstrated how OpenClaw can control an n8n workflow through a webhook. Instead of opening n8n manually every time, we can simply send a message through Telegram. OpenClaw receives the request, calls the n8n workflow, and returns the result directly to us.


This architecture provides a highly flexible way to control automations from a phone, a tablet, or any device on which you can access Telegram. Furthermore, it makes the entire system significantly more stable:


  • Secure Execution: The core workflow logic stays inside n8n.

  • Credential Management: Sensitive credentials and API keys also remain securely within n8n.

  • Simplified AI Tasks: OpenClaw only needs to trigger the workflow and summarize the results.


Ultimately, we have successfully separated the AI agent from the automation pipeline. OpenClaw is responsible for interaction and reasoning, and n8n is responsible for reliable workflow execution. For a complete walkthrough of this process, be sure to watch the full video tutorial embedded at the top of this post.

Comments


bottom of page