routeros-middleware

n8n node for interacting with MikroTik RouterOS via Middleware Service

Package Information

Released: 5 mo ago
Downloads: 22 weekly / 82 monthly
Latest Version: 1.1.6
Author: robioki

Documentation

n8n-nodes-routeros-middleware

npm version
License: MIT

Custom n8n node for interacting with MikroTik RouterOS devices via the MikroTik Billing Automation Middleware.

Features

  • Change PPP Profile: Automatically switch user profiles (e.g., for billing automation - isolir/restore)
  • Enable/Disable Users: Enable or disable PPPoE users
  • Force Reconnect: Force users to reconnect (useful after profile changes)
  • Get Active Sessions: Retrieve all active PPPoE sessions
  • Test Connection: Verify connectivity to MikroTik routers

Installation

Option 1: Community Nodes Store (Recommended)

  1. In your n8n instance, go to Settings → Community Nodes
  2. Click Add and search for n8n-nodes-routeros-middleware
  3. Click Install

Option 2: Manual Installation

cd ~/.n8n
npm install n8n-nodes-routeros-middleware

Then restart n8n.

Configuration

Credentials

This node requires API credentials for the MikroTik Middleware Service:

  • Base URL: The URL where your middleware service is running (e.g., http://localhost:3000)
  • API Key: The API key from your middleware service (defined in the .env file)

Usage Examples

1. Automated Billing Isolation

When a customer hasn't paid, automatically move them to an isolated profile:

Trigger: Billing System Webhook (Overdue Payment)
  ↓
Mikrotik Node: Change Profile
  - Username: {{ $json.customer_username }}
  - Router Name: main-router
  - New Profile: ISOLIR-256K
  - Force Reconnect: true
  ↓
WhatsApp Node: Send Payment Reminder

2. Payment Restoration

When payment is received, restore the customer's internet:

Trigger: Payment Gateway Webhook (Payment Success)
  ↓
Mikrotik Node: Change Profile
  - Username: {{ $json.customer_username }}
  - Router Name: main-router
  - New Profile: HOME-20MB
  - Force Reconnect: true
  ↓
WhatsApp Node: Send Activation Confirmation

3. Get Active Sessions

Monitor active PPPoE sessions:

Trigger: Cron (Every 5 minutes)
  ↓
Mikrotik Node: Get Active Sessions
  - Router Name: main-router
  ↓
Function Node: Process Session Data
  ↓
Database: Store Session History

Operations

Change Profile

Change a PPPoE user's profile (primary operation for billing automation).

Parameters:

  • routerName: The name of the router (as configured in middleware)
  • username: PPPoE username
  • newProfile: Target profile name (e.g., "HOME-20MB", "ISOLIR-256K")
  • forceReconnect: (Optional) Force user to reconnect after profile change (default: true)

Example Response:

{
  "success": true,
  "message": "Profile changed successfully",
  "data": {
    "username": "customer123",
    "oldProfile": "HOME-20MB",
    "newProfile": "ISOLIR-256K",
    "forcedReconnect": true
  }
}

Get Active Sessions

Retrieve all active PPPoE sessions from a router.

Parameters:

  • routerName: The name of the router

Example Response:

{
  "success": true,
  "data": [
    {
      "username": "customer123",
      "address": "192.168.1.100",
      "uptime": "2h30m",
      "profile": "HOME-20MB"
    }
  ]
}

Enable/Disable User

Enable or disable a PPPoE user account.

Parameters:

  • routerName: The name of the router
  • username: PPPoE username

Force Reconnect

Force a PPPoE user to disconnect and reconnect.

Parameters:

  • routerName: The name of the router
  • username: PPPoE username

Test Connection

Test connectivity to a MikroTik router.

Parameters:

  • routerName: The name of the router

Middleware Service

This node requires the MikroTik Billing Automation Middleware to be running and accessible.

Quick Start Middleware

# Clone the repository
git clone https://github.com/robioki/golang-routeros-middleware.git
cd golang-routeros-middleware

# Copy environment file
cp .env.example .env

# Edit .env and set your configuration
nano .env

# Run with Docker
docker-compose up -d

The middleware will be available at http://localhost:3000 by default.

Error Handling

All nodes support Continue On Fail setting:

  • When enabled, the workflow will continue even if the operation fails
  • Error details will be available in the node output under error field
  • Use a Switch node to handle success/failure paths

Common errors:

  • Router not found: Check router name in middleware configuration
  • Invalid credentials: Verify API key in credentials
  • User not found: PPPoE username doesn't exist on router
  • Connection timeout: Router is unreachable or API service is down

Troubleshooting

Node Not Appearing

  1. Make sure the node is installed: npm list n8n-nodes-mikrotik
  2. Restart n8n completely
  3. Check n8n logs for errors

Connection Errors

  1. Verify middleware service is running: curl http://localhost:3000/api/v1/health
  2. Check firewall rules between n8n and middleware
  3. Verify API key in credentials matches middleware API_KEY

Profile Changes Not Working

  1. Check middleware execution logs: docker logs middleware
  2. Verify router credentials in middleware are correct
  3. Test router connection from middleware UI
  4. Check that profile exists on MikroTik router

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

License

MIT License - see LICENSE file for details.

Support

Related Projects

Discussion