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.
Marketing teams, content creators, or social media managers can:
When clicking ‘Execute workflow’Create Search TermSets the value of the hashtag you'd like to scan.
Default is n8n, but you can modify it to anything.
{ "Search_Term": "yourCustomHashtag" }
Find Recent PostsHTTP Query Auth?token=yourTokenHere as the query stringJSON Body:
{
"hashtags": ["{{ $json.Search_Term }}"],
"resultsLimit": 20,
"resultsType": "posts"
}
Set bio and follower countcaption from each post and stores it in a clean variable for the AI agent to use.AggregateConvert table names and columns into single text for agentUses a Code node to combine all captions into a single string for OpenAI to read:
return [
{
json: {
text: items
.map(item => - ${JSON.stringify(item.json)})
.join('\n\n'),
},
},
];
AI AgentTakes the combined post text and sends it to GPT-4o-mini.
Includes this system message:
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"] }
OpenAI Chat Modelgpt-4o-miniStructured Output ParserParses the GPT response into structured JSON:
{ "Post Idea": ["Idea1", "Idea2"], "Most Common Post": ["common post 1", "common post 2"] }
Split Out, Split Out1Post Idea list and Most Common Post list into individual items.MergeRobert Breen
Automation Consultant | AI Workflow Designer | n8n Expert
📧 [email protected]
🔗 LinkedIn


