Integration Guide

How to Connect InstantDM with n8n (Self-Hosted Automation)

Learn how to connect InstantDM with n8n to automate Instagram DM workflows using self-hosted automation. Step-by-step guide to route Instagram leads, sync CRM data, and trigger actions using webhooks.

Meta Business Partner
30,000+ creators
$9.99/mo flat

n8n is an open-source, self-hosted workflow automation tool - think Make.com or Zapier, but running on your own server. Connecting InstantDM to n8n gives you full control over your data, no per-operation pricing, and the ability to build complex Instagram DM automations without vendor lock-in.

This guide covers the full setup: receiving InstantDM webhook events in n8n, processing the data, and calling the InstantDM API to send DMs back.


Why Use n8n with InstantDM?

n8n runs on your infrastructure (a VPS, Docker container, or even a Raspberry Pi), which means:

  • No operation limits - process thousands of Instagram events without worrying about monthly caps
  • Full data ownership - webhook payloads never pass through a third-party automation platform
  • Self-hosted or cloud - run it on your own server or use n8n.cloud for a managed option
  • 200+ integrations - connect Instagram DM data to databases, CRMs, APIs, and internal tools
  • Free and open source - the core platform is free under a fair-code license

Common Use Cases

  • Route Instagram leads to a self-hosted CRM or database
  • Build internal dashboards from DM flow data
  • Trigger custom backend logic when someone completes a flow
  • Sync lead data to PostgreSQL, MySQL, or MongoDB
  • Send Slack/Discord/email alerts without per-message costs
  • Chain multiple API calls in a single workflow

What You'll Need

Requirement Details
InstantDM account Trendsetter, Trendsetter Pro, or any Multi plan (API access required)
n8n instance Self-hosted (Docker, npm, or desktop) or n8n.cloud account
InstantDM API key Found at Settings → API in your InstantDM dashboard
Public URL for n8n Your n8n instance must be reachable from the internet (use a domain or ngrok for testing)

Note: If your n8n instance is running locally (localhost), InstantDM webhooks can't reach it. Use ngrok or a reverse proxy to expose it during development.


Step 1: Generate an API Key in InstantDM

  1. Log in to app.instantdm.com.
  2. Navigate to Settings → API in the left sidebar.
  3. Copy your API Key.
  4. Keep this page open - you'll paste your n8n webhook URL here in Step 3.

Step 2: Create a Webhook Workflow in n8n

  1. Open your n8n instance and click Add workflow.
  2. Click the "+" button to add the first node.
  3. Search for Webhook and select it.
  4. Configure the webhook node:
Setting Value
HTTP Method POST
Path instantdm-events (or any path you prefer)
Authentication None (we'll verify via signature)
Response Mode Immediately (recommended)
  1. Click Listen for Test Event - n8n starts listening on the webhook URL.
  2. Copy the Production URL shown (e.g., https://your-n8n.example.com/webhook/instantdm-events).

Important: n8n has two webhook URLs - a Test URL (only active when you click "Listen for Test Event") and a Production URL (active when the workflow is activated). Use the Production URL in InstantDM.


Step 3: Configure Webhook URL in InstantDM

  1. Go to Settings → API in InstantDM.
  2. Paste the n8n Production URL into the Webhook URL field.
  3. Select which events to forward:
Event When It Fires
comment Someone comments on your post
dm_received Someone sends you a DM
postback User clicks a button in your DM flow
question_answered User answers a question node in a flow
flow_completed User reaches the end of a flow
  1. Click Save.

Step 4: Test the Webhook Connection

  1. In n8n, click Listen for Test Event on the Webhook node.
  2. In InstantDM, click Send Test Webhook (on the Settings → API page).
  3. n8n should receive the test payload and display the data structure.
  4. Click on the webhook node output to inspect the fields.

Example Webhook Payload

{
  "event": "flow_completed",
  "timestamp": "2025-01-15T10:30:00Z",
  "data": {
    "instagram_user_id": "17841400123456789",
    "username": "johndoe",
    "flow_name": "Lead Capture Flow",
    "response_variables": {
      "full_name": "John Doe",
      "email": "john@example.com",
      "phone": "+1234567890",
      "interest": "Premium Plan"
    }
  }
}

Step 5: Process and Route the Data

Now add nodes after the webhook to do something with the data.

Option A: Route by Event Type with a Switch Node

  1. Add a Switch node after the Webhook.
  2. Set the routing field to {{ $json.body.event }}.
  3. Add cases for each event type: comment, dm_received, flow_completed, etc.
  4. Each branch can have its own processing chain.

Option B: Save Leads to a Database

  1. Add a Postgres (or MySQL/MongoDB) node.
  2. Set the operation to Insert.
  3. Map the fields:
Database Column n8n Expression
username {{ $json.body.data.username }}
email {{ $json.body.data.response_variables.email }}
phone {{ $json.body.data.response_variables.phone }}
flow_name {{ $json.body.data.flow_name }}
created_at {{ $json.body.timestamp }}

Option C: Send a Slack Notification

  1. Add a Slack node.
  2. Set the channel and message:
🎯 New Instagram Lead!
Name: {{ $json.body.data.response_variables.full_name }}
Email: {{ $json.body.data.response_variables.email }}
Instagram: @{{ $json.body.data.username }}
Flow: {{ $json.body.data.flow_name }}

Option D: Send an HTTP Request to Your Own API

  1. Add an HTTP Request node.
  2. Configure it to POST to your internal API endpoint.
  3. Pass the webhook data in the request body.

Step 6: Send DMs Back via the InstantDM API

You can use n8n to send Instagram DMs through InstantDM's API.

  1. Add an HTTP Request node.
  2. Configure it:
Setting Value
Method POST
URL https://api.instantdm.com/api-webhook
Authentication Header Auth
Header Name Authorization
Header Value Bearer YOUR_API_KEY
Body Content Type JSON
  1. Set the JSON body:
{
  "action": "send_message",
  "type": "text",
  "recipient_id": "{{ $json.body.data.instagram_user_id }}",
  "message": "Thanks for your interest! We'll be in touch soon."
}

Sending Buttons

{
  "action": "send_message",
  "type": "buttons",
  "recipient_id": "{{ $json.body.data.instagram_user_id }}",
  "message": "What would you like to know more about?",
  "buttons": [
    { "title": "Pricing", "payload": "pricing_info" },
    { "title": "Features", "payload": "features_info" },
    { "title": "Book a Call", "url": "https://calendly.com/yourname" }
  ]
}

Example Workflow: Lead Capture → PostgreSQL → Slack Alert

This workflow saves every completed flow to a database and notifies your team.

Workflow flow: Webhook → IF (event = flow_completed) → Postgres (Insert Row) → Slack (Send Message)

Setup Steps

  1. Webhook node - configured from Steps 2-4.
  2. IF node - condition: {{ $json.body.event }} equals flow_completed.
  3. Postgres node - insert into your leads table with mapped fields.
  4. Slack node - send a formatted message to your #instagram-leads channel.
  5. Activate the workflow (toggle in the top-right corner).

Verifying Webhook Signatures

For production use, verify that webhook requests are genuinely from InstantDM.

  1. Add a Code node right after the Webhook node.
  2. Use this JavaScript:
const crypto = require('crypto');

const signature = $input.first().json.headers['x-webhook-signature'];
const body = JSON.stringify($input.first().json.body);
const apiKey = 'YOUR_API_KEY';

const expectedSignature = crypto
  .createHmac('sha256', apiKey)
  .update(body)
  .digest('hex');

if (signature !== expectedSignature) {
  throw new Error('Invalid webhook signature');
}

return $input.all();
  1. Connect the Code node's output to the rest of your workflow. Invalid requests will throw an error and stop processing.

Deploying n8n for Production

If you're running n8n locally for testing, here's how to deploy it for production use with InstantDM:

Docker (Recommended)

docker run -d \
  --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  -e N8N_HOST=your-domain.com \
  -e N8N_PROTOCOL=https \
  -e WEBHOOK_URL=https://your-domain.com/ \
  n8nio/n8n

Key Production Settings

Setting Purpose
WEBHOOK_URL Must match your public domain so webhook URLs are correct
N8N_PROTOCOL=https Required for secure webhook communication
N8N_BASIC_AUTH_ACTIVE=true Protect the n8n editor with a password
EXECUTIONS_DATA_SAVE_ON_ERROR=all Save failed executions for debugging

Using ngrok for Testing

If you're testing locally:

ngrok http 5678

Use the ngrok HTTPS URL as your webhook URL in InstantDM. Remember to update it when the ngrok session expires.


Troubleshooting

Issue Solution
Webhook not receiving data Ensure your n8n instance is publicly accessible. Check that the workflow is activated (not just in test mode).
"Workflow could not be started" The workflow must be active for the Production URL to work. Click the toggle in the top-right corner.
Data fields are empty Check the expression paths. n8n wraps webhook data in $json.body - make sure you're accessing $json.body.data.username, not $json.data.username.
HTTP Request node returning 401 Verify your API key includes the Bearer prefix in the Authorization header.
Webhook URL changes after restart Set the WEBHOOK_URL environment variable to your public domain so n8n generates consistent URLs.
n8n not accessible from internet Use a reverse proxy (nginx, Caddy) with SSL, or use ngrok for testing.
Duplicate executions Check if you have both the Test and Production webhooks active. Only the Production URL should be used in InstantDM.

Frequently Asked Questions

Is n8n really free?

n8n's core is open source under a "fair-code" license. You can self-host it for free with no operation limits. n8n.cloud is a paid managed hosting option if you don't want to manage your own server.

How does n8n compare to Make.com for InstantDM?

n8n has no per-operation pricing, so it's cheaper at scale. You get full data control since everything runs on your server. The trade-off is you need to manage hosting, updates, and SSL certificates. Make.com is easier to set up but costs more as volume grows.

Can I use n8n.cloud instead of self-hosting?

Yes. n8n.cloud gives you a managed n8n instance with a public URL, so you skip the hosting setup. The webhook URLs work the same way - just copy the Production URL into InstantDM.

How many Instagram events can n8n handle?

There's no platform-imposed limit. Performance depends on your server resources. A basic VPS (2 CPU, 4GB RAM) can handle thousands of webhook events per hour without issues.


What's Next

Ready to Automate Your Instagram DMs?

Join 30,000+ creators and brands using InstantDM today.

Start Your Free Trial

No credit card required. Setup in under 15 minutes.