← Back to Workflows

YouTube Shorts API Integration

Automate YouTube Shorts Data Collection

🔄 n8n 📱 YouTube 🔗 SerpApi ⏱️ 15 min read

Overview

This workflow demonstrates how to automatically fetch YouTube Shorts data using SerpApi and process it with n8n. Perfect for content creators, marketers, and developers who need to track trending shorts or analyze video performance.

What You'll Learn

  • SerpApi Integration: Connect to SerpApi for YouTube Shorts data
  • Data Parsing: Extract and structure shorts_results from API responses
  • Database Storage: Store shorts data in your database
  • Error Handling: Implement fallback logic for missing data
  • Field Mapping: Map API fields to your database schema

Prerequisites

  • n8n instance (cloud or self-hosted)
  • SerpApi account and API key
  • Database for storing results (MySQL, PostgreSQL, etc.)
  • Basic understanding of JSON and APIs

Workflow Architecture

1. Trigger

Schedule or webhook to start the workflow

2. API Request

Fetch YouTube Shorts from SerpApi

3. Parse Data

Extract shorts_results array

4. Store Results

Save to database with proper mapping

Step-by-Step Implementation

Step 1: Set Up the Trigger

Start with a Schedule Trigger node to run the workflow at regular intervals, or use a Webhook node for on-demand execution.

  • Schedule Trigger: Set to run every hour/day based on your needs
  • Webhook Trigger: For manual or API-triggered execution

Step 2: Configure SerpApi Request

Use the HTTP Request node to call the SerpApi YouTube Shorts endpoint:

API Configuration

Method: GET

URL: https://serpapi.com/search

Query Parameters:

  • engine: youtube
  • search_query: your_search_term
  • api_key: your_serpapi_key

Step 3: Parse the Response

The SerpApi response contains a shorts_results array. Use the Code node or Set node to extract this data:

Key Fields in shorts_results

  • title: Video title
  • link: YouTube video URL
  • thumbnail: Thumbnail image URL
  • channel: Channel information
  • views: View count
  • published_date: When the short was published

Step 4: Handle Missing Data

Implement error handling for cases where shorts_results is empty or missing:

  • Use an IF node to check if shorts_results exists
  • Add a fallback path to handle regular video results
  • Log errors for debugging

Step 5: Map Fields to Database Schema

Use the Set node to map API fields to your database columns:

Example Field Mapping

  • API: title → DB: video_title
  • API: link → DB: video_url
  • API: thumbnail → DB: thumbnail_url
  • API: channel.name → DB: channel_name
  • API: views → DB: view_count

Step 6: Store in Database

Use the database node (MySQL, PostgreSQL, etc.) to insert the processed data:

  • Configure your database credentials
  • Use INSERT or UPSERT operations
  • Handle duplicate entries with unique constraints

Common Issues and Solutions

Issue: shorts_results is undefined

Solution: Check the API response structure. SerpApi may return different structures based on the search query. Inspect the raw response and adjust your parsing logic.

Issue: Field mapping errors

Solution: Use the Code node to inspect the exact structure of each item in shorts_results. Log the data to understand the available fields.

Issue: Rate limiting

Solution: Implement delays between requests and respect SerpApi's rate limits. Use the Wait node to add delays if processing multiple queries.

Best Practices

  • Error Logging: Always log API responses for debugging
  • Data Validation: Validate data before inserting into database
  • Duplicate Handling: Use video URLs as unique identifiers
  • Batch Processing: Process multiple search queries efficiently
  • Monitoring: Set up alerts for workflow failures
  • API Key Security: Store API keys in n8n credentials, never hardcode

Use Cases

  • Track trending YouTube Shorts in your niche
  • Analyze competitor short-form content
  • Build a shorts recommendation system
  • Monitor brand mentions in YouTube Shorts
  • Collect data for content strategy research

Extensions and Improvements

Once you have the basic workflow running, you can extend it with:

  • Sentiment analysis on video titles and descriptions
  • Automatic categorization using AI/ML
  • Notifications for viral shorts (high view count)
  • Integration with analytics dashboards
  • Automated reporting via email or Slack