🎬 Generate Instagram captions from hashtag analysis using Apify + GPT-4o-mini

795 views · 🎬 Content Creation & Video

💡 Pro Tip — Heads up — if this workflow’s Instagram scraping breaks (it happens whenever Meta updates their frontend), ScraperNode is a community node that handles profiles, posts, reels, and comments without any HTML parsing.

View All Scrapers

Description

This n8n workflow scrapes recent Instagram posts by hashtag and generates new, relevant caption ideas using OpenAI. It avoids making up suggestions by analyzing real-world content and surfacing common patterns.


✅ Use Case

Marketing teams, content creators, or social media managers can:


🧠 How It Works

1️⃣ Manual Trigger

🧩 Node: When clicking ‘Execute workflow’


2️⃣ Define the Hashtag

🧩 Node: Create Search Term

{
  "Search_Term": "yourCustomHashtag"
}

3️⃣ Scrape Instagram Posts

🧩 Node: Find Recent Posts

JSON Body:

{
  "hashtags": ["{{ $json.Search_Term }}"],
  "resultsLimit": 20,
  "resultsType": "posts"
}

4️⃣ Extract Captions

🧩 Node: Set bio and follower count


5️⃣ Aggregate Captions

🧩 Node: Aggregate


6️⃣ Convert to Single Text Block

🧩 Node: Convert table names and columns into single text for agent

return [
  {
    json: {
      text: items
        .map(item => `- ${JSON.stringify(item.json)}`)
        .join('\n\n'),
    },
  },
];

7️⃣ Generate Caption Ideas with AI

🧩 Node: AI Agent

I'm looking for ideas for posts about {{ $('Create Search Term').item.json.Search_Term }}.
Here’s the last 5 posts on Instagram about the topic. Use those to help me generate a list of relevant captions.

Do not make up ideas that are not like the others in the list.

Output like this:
{
  "Post Idea": ["Idea1", "Idea2"],
  "Most Common Post": ["common post 1", "common post 2"]
}

8️⃣ Choose Language Model

🧩 Node: OpenAI Chat Model


9️⃣ Parse the AI Output

🧩 Node: Structured Output Parser

{
  "Post Idea": ["Idea1", "Idea2"],
  "Most Common Post": ["common post 1", "common post 2"]
}

🔟 Split the Outputs

🧩 Nodes: Split Out, Split Out1


🔁 Merge for Final Output

🧩 Node: Merge


👤 Need More Help?

Robert Breen
Automation Consultant | AI Workflow Designer | n8n Expert
📧 robert@ynteractive.com
🔗 LinkedIn

🔗 Nodes Used

HTTP Request, AI Agent, OpenAI Chat Model, Structured Output Parser

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup