Automate Instagram Content Creation with AI & n8n

This workflow automates generating Instagram posts from trending content using AI for image and caption creation, saving hours for social media managers and creators by handling discovery, analysis, and publishing effortlessly.
facebookGraphApi
openAi
postgres
+9
Workflow Identifier: 1268
NODES in Use: If, Telegram, SplitInBatches, ScheduleTrigger, Set, HttpRequest, Code, Merge, Postgres, OpenAi, FacebookGraphApi, StickyNote

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

1. Opening Problem Statement

Meet Sarah, a social media manager juggling multiple clients. Every day, she spends hours researching trending Instagram content, crafting engaging captions, sourcing or creating images, and scheduling posts. Despite her efforts, the manual process leads to delays and missed optimal posting times, costing her clients engagement and potential revenue. Sarah needs a way to automate content discovery, generation, and publication to keep up with the fast-moving Instagram trends without burning out.

This is precisely the problem solved by the “Generate Instagram Content from Top Trends with AI Image Generation” n8n workflow. It automates from trend discovery through AI content creation to publishing — the entire Instagram posting cycle — dramatically saving Sarah’s time and improving consistency.

2. What This Automation Does

This workflow is a powerful assistant for anyone looking to maintain an active Instagram presence by leveraging current trending posts. Here’s what it does when it runs:

  • Scrapes top posts from Instagram hashtags #blender3d and #isometric to identify current popular content.
  • Filters out videos, focusing only on image posts, ensuring content quality and relevance.
  • Checks a Postgres database to avoid reposting content already shared, maintaining originality.
  • Uses OpenAI’s GPT-4 Vision to analyze images and generate detailed descriptions.
  • Generates engaging Instagram captions with appropriate hashtags based on image content.
  • Leverages Replicate’s Flux AI model to create unique, highly-stylized 3D-isometric images inspired by the trending content.
  • Publishes the generated posts to an Instagram Business Account via Facebook Graph API.
  • Sends Telegram notifications about upload status and errors, keeping the user informed in real-time.

By automating these steps, this workflow saves hours of daily manual work and helps social media pros like Sarah keep content fresh, relevant, and appealing continuously.

3. Prerequisites ⚙️

  • n8n account: With the ability to create and run workflows.
  • Instagram Business Account: Required to publish content via Facebook Graph API.
  • Telegram Bot API Credentials: For receiving status notifications.
  • OpenAI Account: Access to GPT-4 Vision model for image analysis and caption generation.
  • Replicate API Token: To use Flux AI for image generation.
  • RapidAPI Key: For accessing the Instagram scraper API.
  • PostgreSQL Database: To track posted content and avoid duplicates.

⚠️ Optionally, n8n can be self-hosted for more control and scalability. For affordable hosting, visit buldrr.com/hostinger.

4. Step-by-Step Guide

Step 1: Schedule the automation

Navigate to Triggers → Schedule Trigger1, and set the cron expression to “5 13,19 * * *”. This runs the workflow twice daily at 13:05 and 19:05 server time, ensuring fresh content regularly.

Expected: Workflow triggers at scheduled times.

Common mistake: Incorrect cron syntax — double-check before saving.

Step 2: Set up Instagram and Telegram parameters

Go to the Instagram params node and input your Instagram Business Account ID.

Then open the Telegram Params node and enter your Telegram chat ID where notifications should be sent.

Expected: Parameters stored for later use.

Tip: Use the provided sticky notes with official guides on retrieving these IDs.

Step 3: Configure API keys

Fill out the Rapid Api params node with your RapidAPI key for the Instagram scraper service.

Then enter your Replicate API token in the Replicate params node.

Expected: API keys set for authenticating external calls.

Step 4: Fetch trending Instagram posts

Two HTTP Request nodes named get top trends on instagram #blender3d and get top trends on instagram #isometric request the top media from the respective hashtags using RapidAPI.

Both nodes send a GET request with required headers including your RapidAPI key.

Expected: JSON response with arrays of top posts.

Step 5: Filter image-only content

Two Code nodes, filter the image content and filter the image content-2, remove video entries by checking the is_video flag.

The simplified objects include id, prompt (caption), content_code, thumbnail_url, and tag (hashtag name).

Lorem ipsum of the JavaScript filter code:

const filteredData = $input.first().json.data.items.filter(item => !item.is_video);
return filteredData.map(item => ({
  id: item.id,
  prompt: item.caption.text,
  content_code: item.code,
  thumbnail_url: item.thumbnail_url,
  tag: $input.first().json.data.additional_data.name
}));

Expected: Cleaned and simplified image post arrays.

Step 6: Combine trend data streams

The merge the array content node merges trends from both hashtags into a single data stream.

Expected: Single merged list for processing.

Step 7: Loop and check database for duplicates

The Loop Over Items node loops through merged posts one by one.

The Check Data on Database Is Exist node queries the PostgreSQL table top_trends to check if the content code already exists.

If data exists, the If Data is Exist node sends the item back to loop to move on. Otherwise, the workflow proceeds to insert new content.

Database schema snippet from Sticky Note12:

CREATE TABLE top_trends (
  id SERIAL PRIMARY KEY,
  isposted BOOLEAN DEFAULT false,
  createdat TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  prompt TEXT NOT NULL,
  thumbnail_url TEXT,
  code TEXT,
  tag TEXT
);

Expected: Only unique content is processed further.

Step 8: Insert new content into the database

The insert data on db PostgreSQL node saves unique trending posts with isposted set to false.

Expected: Database updated to track new content.

Step 9: Analyze image content with OpenAI GPT-4 Vision

The Analyze Image and give the content node calls OpenAI to generate a detailed description of the image focusing on physical features: shape, texture, size, notable characteristics.

The prompt is crafted to ignore background or lighting, creating concise object descriptions.

Expected: Textual content describing the image stored for caption generation.

Step 10: Generate Instagram caption

The Analyze Content And Generate Instagram Caption node uses OpenAI’s language model to summarize the description into a short, engaging caption under 150 words.

Relevant hashtags like #Blender3D, #3DArt, #DigitalArt are automatically included.

Example prompt snippet:

Summarize the following content description into a short, engaging Instagram caption under 150 words...
Content description to summarize:
{{ $json.content }}
Include hashtags #Blender3D, #3DArt, #DigitalArt, #3DModeling, and #ArtCommunity...

Expected: Ready-to-use caption text.

Step 11: Generate AI image inspired by the trend

The Generate image on flux HTTP Request node sends a POST request to Replicate’s Flux AI model with the OpenAI description prompt, generating a unique, isometric 3D-styled image.

The JSON body includes detailed styling instructions (matte materials, ambient lighting, 4K resolution, no shadows) to ensure a consistent artistic look.

Sample payload excerpt:

{
  "input": {
    "prompt": "A highly detailed 3D isometric model of ...",
    "output_format": "jpg",
    "output_quality": 100
  }
}

Authorization is done with the Bearer token from Replicate params.

Expected: High-quality AI-generated image URL returned.

Step 12: Prepare Instagram media upload

The Prepare data on Instagram Facebook Graph API node uploads the generated image and caption to Instagram via the user’s Business Account.

Expected: Receives media creation ID to proceed with publishing.

Step 13: Check media upload status

The Check Status Of Media Before Uploaded node checks the status code of the uploaded media. If “FINISHED”, the If media status is finished node triggers publication.

If any error occurs, the Telegram node sends an alert message.

Step 14: Publish Instagram post

The Publish Media on Instagram node sends the post live. After publishing, the Check status of post node monitors its status, confirming with If media status is finished1.

Successful publishes trigger a confirmation message via Telegram1. Failures alert via Telegram2.

5. Customizations ✏️

  • Change Hashtags for Trend Discovery: In the HTTP Request nodes “get top trends on instagram #blender3d” and “get top trends on instagram #isometric”, update the hashtag query parameter to your desired niche.
  • Modify AI Image Generation Style: Edit the prompt in the Generate image on flux node’s JSON body to adjust artistic style, materials, and lighting for branding consistency.
  • Adjust Posting Schedule: Change the cron expression in the Schedule Trigger1 node to match your preferred posting times.
  • Expand Caption Hashtags: Add or replace hashtags in the OpenAI caption node prompt to target different audiences.
  • Database Table Name or Schema: Update the Check Data on Database Is Exist and insert data on db nodes if you use a different table or database schema.

6. Troubleshooting 🔧

Problem: “API key not authorized” errors from RapidAPI requests

Cause: Incorrect or expired RapidAPI key.

Solution: Go to the Rapid Api params node and re-enter a valid key. Verify on RapidAPI dashboard your subscription status.

Problem: “Postgresql query error” when checking existing content

Cause: Database connection or schema mismatch.

Solution: Verify PostgreSQL credentials in n8n. Ensure top_trends table exists as per schema. Use the SQL script in Sticky Note12 to create if missing.

Problem: Instagram media upload stuck or fails

Cause: Facebook Graph API issues, invalid media URL, or API permission.

Solution: Check the media URL from Replicate generation. Confirm Instagram Business Account has required permissions. Review error messages sent via Telegram nodes.

7. Pre-Production Checklist ✅

  • Confirm API keys and tokens are valid and entered correctly.
  • Verify Instagram Business Account ID and Telegram chat ID are accurate.
  • Test PostgreSQL connectivity and ensure top_trends table exists.
  • Run the workflow manually first to inspect API responses and error handling.
  • Ensure Telegram bot receives notification messages.
  • Review sticky notes for refresher API guides and rate limits.

8. Deployment Guide

Activate your workflow in n8n by toggling the Active switch after completing configuration.

Monitor the workflow runs from the n8n UI. Look for success logs on data insertion, AI requests, and posting status.

Set up Telegram to instantly notify of any errors or successful posts, keeping you in the loop.

Scaling is simple by adjusting the schedule or adding more hashtags and post-processing steps.

10. Conclusion

By following this guide, you’ve automated the entire Instagram content process from trending post discovery to AI-enhanced image and caption generation, and finally automated publishing. For Sarah, this means hundreds of hours saved yearly and a steady stream of fresh, relevant social media content without lifting a finger.

Next, consider automating cross-posting to other social networks, integrating sentiment analysis for tailored captions, or expanding trend tracking to other platforms like TikTok.

Jump in and let AI and n8n transform your Instagram content strategy effortlessly!

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free