Automated Instagram & Facebook Posting with Meta Graph API - n8n Workflow

Use this comprehensive n8n workflow to automate content publishing across Instagram and Facebook Pages via the Meta Graph API. Features built-in logic for token management and refreshment.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Social Media Managers who need reliable, scheduled cross-posting.
Technical users and developers leveraging the Meta Graph API for automation.
Anyone seeking pre-built n8n templates to manage complex OAuth token lifecycles.
Users aiming to centralize their marketing operations within an n8n environment.

Overview

Managing access tokens for Meta platforms (Facebook and Instagram) can be challenging, as standard user tokens expire quickly. This advanced n8n workflow solves this problem by providing two robust posting mechanisms: a test path using predefined credentials, and a highly recommended production path utilizing long-lived tokens stored via n8n's static data feature.

This n8n workflow seamlessly handles the two-step process required for Instagram posting (creating a media container, then publishing) and dynamically retrieves the necessary Page Access Token for simultaneous Facebook posting. The included guide explains the critical steps for generating a permanent System User Token, ensuring your n8n automation runs without manual token intervention.

How it Works

This n8n workflow is structured into two main operational branches, focusing on token management and social publishing.

1. Token Refresh Automation (Scheduled Maintenance)

This branch uses a dedicated n8n trigger to ensure the access token remains valid. It is configured to run periodically, optimally every 30 days.


  1. Schedule Trigger: The n8n trigger starts the process, configured to run monthly.

  2. Get Current Token (Code n8n node): Retrieves the existing token stored in the workflow's global static data.

  3. Refresh token (HTTP Request n8n node): Uses the Facebook OAuth endpoint and the fbexchangetoken grant type to swap the existing token for a new one, extending its life (typically to 60 days).

  4. Push to Static Data (Code n8n node): The newly acquired, long-lived accesstoken is immediately saved back into the n8n static data store for future use, completing the automated token lifecycle management.

2. Social Publishing (Using Static Data Token)

This sequence executes the actual posting, leveraging the secure token retrieved from static data.


  1. Get Token from static Data (Code n8n node): Retrieves the long-lived token required for all subsequent API calls.

  2. Post to Instagram1 (HTTP Request n8n node): Calls the Meta Graph API's /media endpoint to create the media container, providing the image URL and caption, along with the access token.

  3. Wait 2 Second1 (Wait n8n node): A brief pause is necessary to allow Meta to process the media container.

  4. Publish instagram post1 (HTTP Request n8n node): Calls the /mediapublish endpoint using the creation_id returned from the previous step to finalize the Instagram post.

  5. Use System token to get page token1 (HTTP Request n8n node): Queries the me/accounts endpoint using the secure token to fetch a list of all managed Facebook Pages and their respective Page Access Tokens.

  6. Get Correct Page Token1 (Code n8n node): Filters the list to extract the specific Page Access Token for the target Facebook Page.

  7. Post to Facebook1 (HTTP Request n8n node): Publishes the image and caption directly to the Facebook Page using the derived Page Access Token.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON and import it into your n8n instance.

  2. Set up Meta Graph API Credentials:

You must create a Facebook Graph API credential in n8n.
For production use, it is highly recommended to follow the steps in the Sticky Note to generate a Permanent System User Token.
Enter this token into the Facebook Graph account credential configuration.

  1. Configure Placeholder Values:

In the Post to Instagram (or Post to Instagram1) n8n node, replace , , and with your actual data.
In the Publish instagram post nodes, ensure the correct Instagram Business Account ID is referenced.
For the token refresh path, update the Refresh token n8n node with your Facebook App's Client ID, Client Secret, and an initial short token for the first run.

  1. Initial Token Setup: If using the scheduled refresh path, manually execute the token refresh branch once (from the Schedule Trigger through to Push to Static Data) to save the initial long-lived token into the static data store before scheduling the posting sequence.

Node Details

This n8n workflow leverages several key n8n node types to achieve complex social media integration:

Manual Trigger / Schedule Trigger: These n8n trigger nodes initiate the workflow. The Manual Trigger is useful for testing, while the Schedule Trigger handles the routine 30-day token refresh.
HTTP Request: This fundamental n8n node is used extensively for all interactions with the Meta Graph API. It handles creating media containers, publishing posts, refreshing tokens, and fetching Page Access Tokens. Key configurations include using POST methods, form-urlencoded content type, and relying on predefined Facebook Graph API credentials.
Code: Several Code n8n node instances are used for critical logic:
Get Current Token and Get Token from static Data: Retrieval of the securely stored access token from n8n's workflow static data.
Push to Static Data: Saving the newly refreshed access token after the exchange process.
Get Correct Page Token (and 1): Custom JavaScript logic to iterate through the list of pages received from the API and isolate the specific Page Access Token needed for Facebook publishing by matching the Page ID.


  • Wait: This n8n node introduces a necessary 2-second delay between creating the Instagram media container and publishing it, which is a requirement for the Meta API.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
Brian
Brian

specializing in automation, AI integrations, and workflow optimization. I build high-impact n8n workflows that connect Salesforce, Outlook, RingCentral, and more. Reach out if you need help making your systems talk to each other.

Featured*