Opening Problem Statement
Meet Sarah, a freelance digital artist hoping to grow her Instagram audience by posting art that resonates with her followers. She finds herself spending 8+ hours a week just searching for trendy content ideas, drafting captions, and creating eye-catching images from scratch. Despite her efforts, duplications and uninspired captions often lead to reduced engagement. Sarah dreams of a system that can automate this tedious process, keeping her account active with fresh content aligned to trending topics without her constant intervention.
This is precisely the problem tackled by our n8n workflow: automating Instagram content generation by tapping into top Instagram trends, leveraging AI for image analysis and regeneration, caption creation, and streamlined posting. This drastically reduces the time commitment, eliminates repetitive manual checks, and ensures Sarah’s posts remain relevant and engaging.
What This Automation Does ⚙️
When you activate this workflow, here’s what happens automatically:
- Scheduled Trend Scraping: At specific times daily (1:05 PM and 7:05 PM Istanbul time), the workflow scrapes Instagram for top posts under hashtags like
#blender3dand#isometric. - Content Filtering and Deduplication: Filters out videos, keeping only image-based posts, then checks a PostgreSQL database to ensure content isn’t duplicated.
- AI Image Analysis: Uses OpenAI’s GPT-4 Vision to analyze images and extract clear, descriptive content details focusing on the object features.
- Caption Generation: Automatically generates engaging Instagram captions tailored for 3D modeling and digital art communities with relevant hashtags.
- AI-Driven Image Generation: Sends the descriptive prompt to Flux AI (via Replicate API) to generate a unique yet visually similar image styled as a 3D isometric miniature toy model.
- Automated Instagram Posting: Uploads the AI-generated image and caption to your Instagram Business account and monitors the publishing status.
- Status Notifications: Sends real-time status updates and error alerts through Telegram bot messages.
Impact: Saves Sarah 8+ hours of manual content preparation weekly and ensures fresh, exclusive posts inspired by trending topics without repeated content.
Prerequisites ⚙️
- n8n account for workflow automation setup ⏱️
- Instagram Business Account linked via Facebook Graph API 🔐
- Telegram Bot API credentials for status notifications 💬
- OpenAI API key for GPT-4 Vision image analysis and caption generation 🔐
- Replicate API token access for Flux AI image generation 🔑
- RapidAPI key with subscription to Instagram Scraper API for top trend data 📊
- PostgreSQL database for storing and de-duplicating Instagram post metadata 📁
- Optional: Self-hosting option for n8n (recommend Hostinger)
Step-by-Step Guide
1. Set Up Scheduled Trigger
Navigate in n8n to Triggers → Schedule Trigger. Configure the cron expression for 5 13,19 * * * to run the workflow daily at 1:05 PM and 7:05 PM Istanbul time. This schedules automatic scraping of trending posts.
Outcome: Workflow initiates as per schedule.
Tip: Confirm your n8n instance timezone matches ‘Europe/Istanbul’ in workflow settings.
2. Configure API Credentials
Fill in your Instagram Business Account ID, Telegram chat ID (from bot setup and chat with it), RapidAPI key for Instagram Scraper, OpenAI key, and Replicate token in their respective Set nodes:
Instagram paramsnode → instagram_business_account_idTelegram Paramsnode → telegram_chat_idRapid Api paramsnode → x-rapid-api-keyReplicate paramsnode → replicate_token
Expected: All credentials correctly stored in workflow context.
3. Fetch Top Trends by Hashtag
Two HTTP Request nodes get top trends on instagram #blender3d and get top trends on instagram #isometric call the Instagram Scraper API via RapidAPI with GET requests, querying top posts under these hashtags.
Note: API headers include ‘x-rapidapi-host’ and your assigned ‘x-rapidapi-key’.
Outcome: Receive JSON data with trending Instagram posts.
4. Filter Out Videos and Merge Arrays
Two Code nodes filter the image content and filter the image content-2 use JavaScript to remove video posts and map the image posts to a simplified object containing id, caption, code, thumbnail URL, and tag.
Then a Merge node combines these filtered arrays into one cohesive list.
5. Loop Over Items and Check Database for Duplicates
The SplitInBatches node Loop Over Items processes each image post in batches.
Each image’s unique ‘content_code’ is checked in the Postgres node Check Data on Database Is Exist against the ‘top_trends’ table to avoid reposting existing content.
6. Insert New Posts to Database
If the image post doesn’t exist in the database (checked by If Data is Exist node), the workflow insert data on db adds the new record with prompt, thumbnail URL, code, and hashtag tag, marking it as not posted.
7. Analyze Image Content Using OpenAI GPT-4 Vision
The Analyze Image and give the content node sends the thumbnail URL to OpenAI’s image analysis model to generate a concise description of the object in the image, focusing on physical features without environmental distractions.
8. Generate Instagram Caption with AI
The Analyze Content And Generate Instagram Caption node uses OpenAI again, this time generating an engaging caption for Instagram under 150 words. It includes relevant hashtags like #Blender3D, #3DArt, and #DigitalArt.
9. Create AI-Generated Image via Replicate API (Flux AI)
The descriptive prompt is passed to the Generate image on flux HTTP Request node, calling Replicate’s Flux AI to generate a new, unique 3D isometric style image.
The POST request includes headers (Authorization: Bearer with Replicate token) and a JSON body specifying the prompt and rendering details like matte textures, lighting, and resolution.
10. Prepare & Upload Content to Instagram
The Prepare data on Instagram Facebook Graph API node uploads the generated image URL and generated caption to your Instagram Business Account as unpublished media.
11. Monitor Upload Status and Publish
Two Facebook Graph API nodes Check Status Of Media Before Uploaded and Check status of post monitor the uploaded media status codes.
If the status updates to FINISHED, the image is published using Publish Media on Instagram.
12. Telegram Notifications About Status
Multiple Telegram nodes send status messages:
- Errors during upload or database operations.
- Successful publishing confirmation.
- Warnings if expected statuses fail.
Customizations ✏️
- Change Hashtags to Scrape: In
get top trends on instagram #blender3dandget top trends on instagram #isometricnodes, edit the “hashtag” query parameter to any preferred niche hashtag to fit your content focus. - Modify Image Generation Style: Adjust the JSON body in the
Generate image on fluxnode to change stylistic parameters such as textures, lighting, or resolution for different art styles. - Customize Captions: Edit the prompt in the
Analyze Content And Generate Instagram Captionnode to add different hashtags or change tone to match your brand voice. - Adjust Schedule Times: Modify the cron expression in the
Schedule Trigger1node to post content at different times for your audience. - Database Table Structure: Customize the
top_trendsPostgreSQL table schema (shown in Sticky Note12) to add fields like post engagement or source URL if you wish to track more metrics.
Troubleshooting 🔧
- Problem: “Instagram Scraper API returns no data or errors.”
- Cause: API key expired, or monthly request quota exceeded.
- Solution: Renew subscription or check quota limits on RapidAPI dashboard.
- Problem: “OpenAI nodes fail to analyze images or generate captions.”
- Cause: Incorrect API key or exceeded usage limits.
- Solution: Verify OpenAI credentials and account status, check model availability.
- Problem: “Instagram publishing hangs or fails with ‘status_code’ not changing to FINISHED.”
- Cause: Issues with Facebook Graph API permissions or network delays.
- Solution: Verify Facebook Graph API credentials, ensure Instagram Business account permissions are set correctly, retry upload.
- Problem: “Telegram bot messages not sending.”
- Cause: Bot not started by sending /start message or wrong Chat ID.
- Solution: Start bot by messaging it first, verify chat ID with Telegram API.
Pre-Production Checklist ✅
- Verify Instagram Business Account ID and Facebook Graph API credentials are active and valid.
- Confirm Telegram Bot is set up, sent a message to, and chat ID is correct.
- Ensure RapidAPI Instagram Scraper subscription is not expired and keys are accurate.
- Test OpenAI and Replicate API keys with small manual requests.
- Validate that PostgreSQL database table ‘top_trends’ exists and schema is correct per Sticky Note12.
- Run workflow manually to check for errors before scheduling.
Deployment Guide
Activate your workflow by toggling it to “active” in the n8n editor. Monitor its initial runs via the execution log to catch any failed nodes.
Set up alerting by linking Telegram nodes for notifications about failures or successful posts, ensuring you stay updated without manual checks.
Consider recurring review of your RapidAPI usage and Instagram account limitations to avoid disruption.
FAQs
- Can I use another image generation service instead of Flux AI?
Yes, replace theGenerate image on fluxHTTP Request node with your preferred AI image generation API, adjusting the request body accordingly. - Does this consume a lot of API calls?
It depends on your schedule and number of posts scraped. Monitor your RapidAPI and OpenAI usage carefully to avoid hitting quota limits. - Is my Instagram content secure?
Your credentials are stored securely in n8n’s credential manager, but always protect your API keys and limit exposure. - Can this workflow handle many hashtags or high volume?
With slight node expansions (e.g., more SplitInBatches or Merge nodes), yes, but monitor API rate limits closely.
Conclusion
By deploying this detailed n8n workflow, you have automated the challenging task of sourcing trending Instagram content, analyzing images, crafting AI-powered captions, and generating fresh images in a unique style—all posted automatically to your Instagram Business account.
This not only saves you more than 8 hours weekly but also ensures your feed stays unique, relevant, and engaging with minimal manual effort.
Next, consider expanding to multi-platform posting, integrating user comments analysis, or adding sentiment-based content filters to boost engagement further.
With this powerful automation, Sarah and creators like her can focus more on their art and less on content logistics.