# Social Media Automation (n8n)
An automated workflow that manages dual-platform social media posting from a Google Sheets content database. Built on n8n, this workflow eliminates manual posting while ensuring content quality through pre-publish validation.
Workflow Architecture
Workflow Nodes
| Node | Purpose |
|---|---|
Get Ready | Schedule trigger: Daily 5:00 PM IST |
Get Content Database | Read from Google Sheet "Myth vs Truth v2" |
Filter Unposted Content | IF: status = "pending" |
Sort by Row ID | Ensure FIFO processing order |
🔢 Limit to 1 Post | Process one post per run |
🔍 Validate Image URL | HEAD request to verify image accessibility |
✅ Image Valids? | IF: statusCode=200 AND content-type=image/* |
⚙️ Configure Post Settings | Set node, post_type, image_url, captions |
📘 Facebook Post | POST to Facebook Graph API /photos |
📷 Instagram Container | Create media container via Graph API |
⏰ Initial Processing Wait | Wait for Instagram media processing |
🔍 Check Instagram Status | Query container status_code |
✅ Is Instagram Ready? | IF: status_code = "FINISHED" |
⏰ Retry Wait Loop | Retry loop for pending containers |
📤 Publish Instagram | Publish container via /media_publish |
📊 Update Status & Post IDs | Update sheet: status=posted, instagram_post_id, facebook_post_id |
📢 Success Notification | Telegram alert with post IDs |
⚠️ Validation Error Alert | Telegram + sheet update on validation failure |
Data Flow
Input: Google Sheet Structure
| Column | Description |
|---|---|
instagram_id | Instagram account ID |
facebook_id | Facebook page ID |
post_type | Type of post (image, video, etc.) |
image_url | Direct URL to image |
caption | Default caption (fallback) |
instagram_caption | Platform-specific caption for Instagram |
facebook_caption | Platform-specific caption for Facebook |
video_url | URL for video posts |
cover_image | Thumbnail for video posts |
status | pending / posted / validation_failed |
instagram_post_id | (filled after posting) |
facebook_post_id | (filled after posting) |
Processing Pipeline
API Integration Details
Facebook Graph API
// Node: 📘 Facebook Post
{
method: "POST",
node: facebook_page_id, // From sheet: facebook_id
edge: "photos",
query: {
message: facebook_caption,
url: image_url,
published: "true"
}
}Instagram Graph API (Two-Step)
// Step 1: Create Media Container
// Node: 📷 Instagram Container
{
method: "POST",
node: instagram_id, // From sheet: instagram_id
edge: "media",
query: {
image_url: image_url,
caption: instagram_caption
}
}
// Returns: container_id
// Step 2: Publish Container (after status = FINISHED)
// Node: 📤 Publish Instagram
{
method: "POST",
node: instagram_id,
edge: "media_publish",
query: {
creation_id: container_id
}
}
// Returns: instagram_post_idImage Validation
// Node: 🔍 Validate Image URL
{
method: "HEAD",
url: image_url,
options: {
timeout: 5000,
redirect: { maxRedirects: 5 }
}
}
// Validation: ✅ Image Valids?
{
conditions: [
statusCode == 200,
content-type == "image/jpeg" OR "image/png"
]
}Error Handling
Validation Failure Path
🔍 Validate Image URL
↓ (failed)
⚠️ Validation Error Alert → Telegram notification
↓
📝 Mark Validation Failed → Update sheet: status='validation_failed'Instagram Processing Retry
⏰ Initial Processing Wait (wait for media processing)
↓
🔍 Check Instagram Status → GET /{container_id}?fields=status_code
↓
✅ Is Instagram Ready?
├── YES → 📤 Publish Instagram
└── NO → ⏰ Retry Wait Loop → Check again (loop)Error Workflow
The workflow is configured with an error workflow for handling unexpected failures:
- Error Workflow ID:
j44unWD08cU7Buhc - Caller Policy: Workflows from same owner only
Telegram Notifications
Success Notification
✅ Post Successfully Published
📱 Instagram: Published with ID: {instagram_post_id}
📘 Facebook: Published with ID: {facebook_post_id}
📄 Caption: {caption.substring(0, 100)}...
🖼️ Image: {image_url}
✅ Status: {statusCode} : {statusMessage}
⏰ Time: {current_timestamp}Validation Failure Alert
❌ Image Validation Failed
🚫 Issue: Image URL is not accessible or invalid
🖼️ URL: {image_url}
📄 Caption: {caption.substring(0, 100)}...
⚠️ Action Required: Please check and update the image URL in the spreadsheet.
🚫 Status: {statusCode} : {statusMessage}
⏰ Time: {current_timestamp}Configuration
Credentials
| Credential | Purpose |
|---|---|
Google Sheets account | OAuth2 for reading/writing sheets |
Facebook Aatmanova n8n new | Facebook Graph API for posting |
Aatmanova I N8N | Instagram Graph API (via Meta) |
Alert x Aatmanova | Telegram Bot for notifications |
Query Auth Aatmanova I N8N | HTTP Query Auth for status checks |
Schedule Settings
| Setting | Value |
|---|---|
| Trigger | Schedule trigger |
| Time | 17:00 (5:00 PM) daily |
| Timezone | Asia/Kolkata (UTC+05:30) |
Key Design Decisions
Why Single Post Per Run?
Processing one post per execution ensures:
- Idempotency: Easy to retry on failure without complex state management
- Rate Limiting: Respects Meta API limits
- Error Isolation: One failure doesn't block subsequent posts
- Auditability: Each post can be tracked individually
Why Two-Step Instagram Posting?
Instagram's API requires:
- Create container → Get container_id
- Wait for processing → Check status
- Publish container → Get post_id
This asynchronous design prevents the workflow from blocking while Meta processes media.
Why Image Validation?
Pre-validating image URLs prevents:
- Failed posts that waste API quota
- Broken images on social platforms
- User confusion when posts silently fail
Why Telegram Notifications?
Immediate visibility into:
- Successful posts (confirmation)
- Failed validations (action required)
- API errors (debugging)
Use Cases
This workflow powers content scheduling for social media campaigns:
- Content Calendar: Team populates Google Sheet with planned posts
- Approval Workflow: Mark posts as "pending" when ready to publish
- Automated Publishing: Workflow runs daily, picks up pending content
- Cross-Platform Sync: Single entry posts to both Facebook and Instagram
- Audit Trail: Post IDs tracked in sheet for performance monitoring
Scalability Considerations
| Aspect | Current | Scaling Options |
|---|---|---|
| Post frequency | 1 post/day | Increase schedule or add parallel branches |
| Multi-account | Single account | Clone workflow nodes for additional accounts |
| Content sources | Google Sheets | Add WordPress, RSS, API sources |
| Notifications | Telegram | Add Email, Slack, Discord |
Portfolio Context
This n8n workflow demonstrates:
- Low-code automation for business processes
- Multi-platform API integration (Facebook, Instagram, Google, Telegram)
- Error handling with retry logic and notifications
- Workflow design for production reliability
Architecture Feedback
Spotted a potential optimization or antipattern? Let me know.