n8n Facebook Instagram Meta API: Content Automation

I connect Facebook and Instagram to n8n because manual social media management doesn’t scale. When I manage content across multiple accounts for clients, the Meta APIs give me programmatic control over posts, ads, and audience data. n8n is the glue that turns API responses into automated workflows.

The Meta Graph API covers both Facebook Pages and Instagram Business accounts through a single interface. I used to juggle four different dashboards — Facebook Business Manager, Meta Ads Manager, Instagram app, and a scheduling tool. Now n8n handles it all from one canvas.

Fetching and Publishing Content

The core workflow starts with fetching content from your sources and publishing to Meta platforms. I use the HTTP Request node to call Graph API endpoints directly. This gives me more control than the pre-built nodes for edge cases.

Here’s how I publish a post to a Facebook Page:

`javascript
// HTTP Request node configuration
Method: POST
URL: https://graph.facebook.com/v18.0/{{page_id}}/feed
Body (JSON):
{
“message”: “{{post_text}}”,
“access_token”: “{{page_access_token}}”
}
`

For Instagram, the approach is similar but requires the Instagram Business account ID and a content_type parameter:

`javascript
// Publish Instagram post
Method: POST
URL: https://graph.facebook.com/v18.0/{{ig_account_id}}/media
Body (JSON):
{
“image_url”: “{{image_link}}”,
“caption”: “{{post_caption}}”,
“access_token”: “{{ig_access_token}}”,
“content_type”: “photo”
}
`

After creating the Instagram media container, I post it to the feed:

`javascript
// Publish Instagram media to feed
Method: POST
URL: https://graph.facebook.com/v18.0/{{ig_account_id}}/media_publish
Body (JSON):
{
“creation_id”: “{{container_id}}”,
“access_token”: “{{ig_access_token}}”
}
`

The page access token comes from Meta’s Graph API Explorer. I generate it with pages_manage_posts and instagram_content_publish permissions. Tokens expire after 60 days, so I refresh them automatically using a cron-triggered workflow that calls the /oauth/access_token endpoint.

I schedule posts by combining the HTTP Request node with n8n’s Cron node. A weekly cron fires on Monday mornings, reads a CSV of scheduled content, and pushes each post at the configured time using the Execute Workflow node with delay settings.

Managing Ad Campaigns and Audience Insights

Beyond organic posts, I automate ad campaign management through the Marketing API. n8n’s HTTP Request node handles campaign creation, budget adjustments, and performance reporting.

Here’s a workflow I run weekly:

`javascript
// Update ad set budget based on performance
Method: POST
URL: https://graph.facebook.com/v18.0/{{ad_set_id}}
Body (JSON):
{
“daily_budget”: “{{new_budget}}”,
“access_token”: “{{ad_account_token}}”
}
`

The budget calculation happens in an n8n Code node. I fetch the previous week’s ROAS (return on ad spend) data, then apply rules:

`javascript
// Code node: adjust budget based on ROAS
const roas = items[0].json.roas;
let budgetChange = 0;

if (roas > 4) {
budgetChange = 25; // Increase by 25%
} else if (roas > 2) {
budgetChange = 10; // Increase by 10%
} else if (roas < 1) { budgetChange = -50; // Cut by 50% }

const newBudget = Math.round(items[0].json.daily_budget * (1 + budgetChange / 100));
return [{ json: { …items[0].json, new_budget: newBudget } }];
`

Audience insights come from the /insights endpoint. I pull reach, engagement, and demographic data daily, store it in a spreadsheet, and trigger alerts when metrics drop below thresholds. The If node routes low-performing campaigns to a review queue while healthy ones continue running.

For Instagram-specific metrics, I query the /accounts/{ig_id}/insights endpoint with metric parameters like followers_count, profile_views, and media_count. These feed into a weekly report that I email to clients using the Gmail node.

Connecting to Your Existing Setup

If you’re running n8n in Docker, the n8n Docker Deployment guide covers the container setup. All API tokens and credentials store in n8n’s encrypted credential store.

The n8n Docker Environment Variables reference lists the variables you need for production-grade Meta API integrations, especially around rate limiting and retry logic.

For webhook-based notifications, the n8n Slack & PagerDuty nodes guide shows how to alert your team when a post fails to publish or an ad account gets flagged.

Action Card: Quick Facebook Post

Test your Meta connection with this minimal workflow:

`javascript
// 1. Create a new Item (manual trigger)
// Set these values:
// page_id = YOUR_FACEBOOK_PAGE_ID
// post_text = Hello from n8n!
// page_access_token = YOUR_PAGE_ACCESS_TOKEN

// 2. HTTP Request node:
// Method: POST
// URL: https://graph.facebook.com/v18.0/{{$json.page_id}}/feed
// Body: {“message”:”{{$json.post_text}}”,”access_token”:”{{$json.page_access_token}}”}

// 3. Response node: check for id field (post created successfully)
`

Verify the post appears on your Facebook Page. If you get an invalid token error, regenerate it from Meta’s Access Token Tool with the right permissions.

References

  • Meta Graph API Documentation
  • Instagram Basic Display API
  • Meta Marketing API
  • n8n HTTP Request Node
  • Access Token Debugger
  • Leave a Reply

    Your email address will not be published. Required fields are marked *