Quick overview
This workflow receives an Instagram username via webhook, checks Supabase for a recent cached analysis, and if needed scrapes recent posts with Apify and generates niche, content, and engagement insights using Google Gemini before storing and returning the report.
How it works
- Receives a POST webhook request containing an Instagram username.
- Queries the Supabase
reports table for matching records updated within the last 24 hours and returns the cached analysis_report if found.
- If no fresh cache exists, runs the Apify Instagram Scraper actor to fetch the latest 5 posts for the requested profile.
- Cleans and bundles the scraped post data into a compact JSON payload for analysis.
- Sends the payload to Google Gemini to generate three sub-reports: niche/frequency, content strategy, and engagement/actions.
- Combines the three Gemini outputs into a single
analysis_report object along with the scraped data.
- Upserts the report into Supabase (update if the username exists, otherwise insert) and returns the fresh
analysis_report in the webhook response.
Setup
- Create or select a Supabase project, add Supabase credentials in n8n, and ensure a
reports table exists with at least username, analysis_report, scraped_data, and updated_at columns.
- Add an Apify API token in n8n and ensure the workflow can run the
apify/instagram-scraper actor with access to the target profiles.
- Add Google Gemini (PaLM) API credentials in n8n for the Gemini model used in the three analysis steps.
- Copy the production webhook URL from the webhook trigger and configure your source app (e.g. Lovable) to POST a JSON body containing
username to /analyze-profile.