17-node n8n workflow using Apify, OpenAI, and Google Sheets to match Facebook ads to Amazon product listings.
A 17-node competitive intelligence pipeline that reverse-engineers what products Facebook advertisers are selling on Amazon. This workflow scrapes the Facebook Ad Library via Apify, uses OpenAI to extract product names from ad creative and copy, then searches Amazon (also via Apify) to find the exact listings. It is the kind of research tool that turns hours of manual competitor analysis into a single automated run.
| Nodes | Category | Complexity | Key Integrations |
|---|---|---|---|
| 17 | E-Commerce / Research | Intermediate | Apify (Facebook + Amazon), OpenAI, Google Sheets |
30-40 minutes including Apify actor setup, OpenAI credential connection, and Google Sheets template preparation.
This workflow starts by querying the Facebook Ad Library through Apify's scraping infrastructure. It pulls active ads from specified advertisers or categories, capturing ad creative, copy text, landing page URLs, and engagement metrics. The raw ad data feeds into a dual-path processing pipeline.
The first path handles ads that link directly to Amazon product pages. These URLs are parsed and the ASINs are extracted directly -- no AI needed. The second path handles ads that do not link to Amazon. OpenAI analyzes the ad creative and copy text to extract the most likely product name, which is then used to search Amazon via a second Apify scraper.
Both paths converge at a filtering and deduplication stage that removes irrelevant results, scores matches by confidence, and writes the final product-to-ad mapping to Google Sheets. The result is a clean spreadsheet linking Facebook advertising activity to specific Amazon product listings.
Triggers
Scraping
AI & Extraction
Logic & Processing
Storage
Manual Trigger -- The workflow starts on demand. Input parameters define the target advertisers, ad categories, or keywords to search in the Facebook Ad Library.
Facebook Ad Scraping -- An HTTP Request node calls Apify's Facebook Ad Library scraper. The scraper returns ad creative URLs, ad copy text, landing page destinations, advertiser names, and activity dates for all matching ads.
URL Analysis -- An IF node examines each ad's landing page URL. Ads linking directly to Amazon URLs (containing amazon.com/dp/ or ASIN patterns) take the direct extraction path. All other ads take the AI extraction path.
Direct Path: ASIN Extraction -- For Amazon-linked ads, a Code node parses the ASIN directly from the URL. No AI is needed -- the product identifier is embedded in the link structure.
AI Path: Product Name Extraction -- For non-Amazon ads, OpenAI analyzes the ad copy and creative description to identify the most likely product name. The AI accounts for branded language, promotional phrasing, and indirect product references to extract a clean, searchable product name.
Amazon Product Search -- The extracted product names are sent to Apify's Amazon scraper in batches. The Split In Batches node manages throughput to respect API rate limits. Each search returns matching Amazon product listings with titles, prices, ratings, and ASINs.
Filtering and Scoring -- A Code node scores each Amazon result against the original ad data. Exact title matches score highest, partial keyword matches score lower, and irrelevant results are filtered out. The Filter and Limit nodes ensure only high-confidence matches pass through.
Results Storage -- The final matched products are written to Google Sheets with full attribution: the original Facebook ad, the advertiser, the matched Amazon listing, the match confidence score, and the product details.
Dual-scraper architecture via Apify. Using Apify for both Facebook Ad Library and Amazon scraping provides consistent, reliable data extraction without building custom scrapers. Apify handles anti-bot measures, rate limiting, and page rendering for both platforms.
AI product name extraction. When ads do not link directly to Amazon, OpenAI extracts the product name from ad creative -- cutting through marketing language, brand names, and promotional copy to identify what is actually being sold. This is the step that makes the workflow usable for the majority of ads that do not include direct Amazon links.
Dual-path logic. The IF-based branching handles both scenarios efficiently: direct Amazon URLs are processed instantly via string parsing, while non-Amazon ads go through the AI extraction pipeline. This minimizes unnecessary AI calls and reduces both latency and cost.
Tip: Key Techniques
Apify for Multi-Platform Scraping -- Apify provides pre-built scrapers for both Facebook and Amazon, eliminating the need to build and maintain custom scraping infrastructure. This significantly reduces development time and ongoing maintenance.
Dual-Path Processing -- When different input types require different processing approaches, use IF nodes to branch early. Direct Amazon URLs are cheap to process (string parsing); non-Amazon ads are expensive (AI extraction). Branch early to minimize unnecessary AI calls.
Batch Processing with Rate Limits -- The Split In Batches node is essential when downstream APIs have rate limits. Process items in controlled batches rather than firing all requests simultaneously, which prevents API throttling and ensures reliable completion.
The workflow.json file in this folder can be imported directly into your n8n instance via Settings > Import Workflow.
I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.