Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@maniwrld/marzjs

maniwrld44AGPL-3.0-only1.0.9

A powerful and easy-to-use Node.js client for interacting with Marzban's VPN management API. It supports popular protocols like Xray, V2Ray, and more.

marzban, api, vpn, nodejs, proxy, xray, v2ray, v2rayng, hiddify, hysteria2, singbox, javascript, client, networking, http, websocket, axios

readme

🌐 MarzJS

A powerful and easy-to-use Node.js client for interacting with the Marzban Panel API.

🚀 Features

  • 💡 Full API coverage for Marzban
  • 🔒 Secure authentication (token-based and credentials-based)
  • 🔄 Comprehensive method support
  • 🧩 Easy-to-use interface
  • 📊 WebSocket log streaming
  • ♻️ Automatic retry mechanism for network requests

📦 Installation

npm install @maniwrld/marzjs

🛠 Quick Start

Authentication Methods

const MarzbanAPI = require('@maniwrld/marzjs');

// Option 1: Authentication with username and password
const client = new MarzbanAPI({
  domain: 'your-marzban-server.com',
  port: 8000,
  username: 'admin',
  password: 'your-password',
  ssl: true  // Optional: use HTTPS/WSS
});

// Option 2: Authentication with token (skip credentials)
const clientWithToken = new MarzbanAPI({
  domain: 'your-marzban-server.com',
  port: 8000,
  token: 'your-access-token',
  ssl: true  // Optional: use HTTPS/WSS
});

// Option 3: Customize retry and timeout settings
const robustClient = new MarzbanAPI({
  domain: 'your-marzban-server.com',
  port: 8000,
  username: 'admin',
  password: 'your-password',
  ssl: true,
  timeout: 15000,        // Custom timeout (ms)
  retryDelay: 2000,      // Delay between retries (ms)
  maxRetries: 5          // Maximum number of retries
});

🌟 Key Methods

👤 Admin Operations

📊 User Management

🔗 Subscription Handling (Under user class)

📝 Template Management

🖥 Node Operations

🌐 System Insights

💻 Core System Management

🔌 WebSocket Logging

client.connectToLogs({
  interval: 1,  // Log polling interval
  onMessage: (logData) => {
    console.log('Received log:', logData);
  },
  onError: (error) => {
    console.error('WebSocket error:', error);
  }
});

// Don't forget to disconnect when done
client.disconnectFromLogs();

🔧 Configuration Options

When initializing the MarzJS client, you can customize the following parameters:

  • domain: Your Marzban server domain (required)
  • port: Server port (required)
  • username: Admin username (optional if using token)
  • password: Admin password (optional if using token)
  • token: Authentication token (optional alternative to username/password)
  • ssl: Use HTTPS/WSS (default: false)
  • timeout: Request timeout in milliseconds (default: 10000)
  • retryDelay: Delay between retry attempts in milliseconds (default: 1000)
  • maxRetries: Maximum number of retry attempts (default: 3)

🛠 Troubleshooting

Common Connection Issues

  1. Authentication Failures

    • Symptom: Repeated 401 or 403 errors
    • Possible Causes:
      • Incorrect domain or port
      • Expired or invalid credentials
      • Network restrictions
    • Solutions:
      // Double-check your connection parameters
      const marzban = new MarzbanAPI({
        domain: 'correct-domain.com',
        port: 8080,
        username: 'admin',
        password: 'correct-password',
        ssl: true
      });
  2. Network Timeout Errors

    • Symptom: Requests timing out frequently
    • Possible Causes:
      • Slow network connection
      • Server under heavy load
      • Firewall restrictions
    • Solutions:
      // Increase timeout and retry settings
      const robustClient = new MarzbanAPI({
        domain: 'example.com',
        timeout: 30000,        // Increased to 30 seconds
        retryDelay: 3000,      // 3 seconds between retries
        maxRetries: 5          // More retry attempts
      });
  3. WebSocket Connection Problems

    • Symptom: Unable to establish log streaming connection
    • Possible Causes:
      • Incorrect SSL configuration
      • Firewall blocking WebSocket
      • Incorrect API permissions
    • Solutions:
      try {
        client.connectToLogs({
          interval: 2,  // Adjust polling interval
          onError: (error) => {
            console.error('Detailed WebSocket error:', error);
            // Implement reconnection logic if needed
          }
        });
      } catch (error) {
        console.error('Log connection initialization error:', error);
      }

Debugging Tips

  • Enable Verbose Logging: Use Node.js debugging tools or environment variables to get more detailed error information
  • Check Marzban Panel Logs: Cross-reference with server-side logs for comprehensive troubleshooting
  • Verify API Endpoint: Ensure your Marzban Panel is running and accessible

Getting Help

  • GitHub Issues: Open an issue with detailed error logs
  • Community Support: Check project discussions for known issues
  • Provide Detailed Information:
    • Node.js version
    • MarzJS version
    • Complete error message
    • Minimal reproducible example

💡 Examples

💻 Get current admin

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.admin.getCurrentAdmin();
    console.log(response)
  } catch (error) {
    console.error(`Error getting current admin:`, error.message);
  }
})();

💻 Create a admin

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const admin_data = {
      "username": "chilladmin",
      "is_sudo": true,
      "telegram_id": 0,
      "discord_webhook": "",
      "password": "securepasswordhopefully"
    }
    const response = await marzban.admin.createAdmin(admin_data);
    console.log(response)
  } catch (error) {
    console.error(`Error creating admin:`, error.message);
  }
})();

💻 Modify a admin

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_admin = "chilladmin";
    const admin_data = {
      "password": "hopefullysecurethistime",
      "is_sudo": true,
      "telegram_id": 0,
      "discord_webhook": ""
     }
    const response = await marzban.admin.modifyAdmin(target_admin, admin_data);
    console.log(response)
  } catch (error) {
    console.error(`Error modifying admin:`, error.message);
  }
})();

💻 Remove a admin

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_admin = "notchilladmin";
    const response = await marzban.admin.removeAdmin(target_admin);
    console.log(response)
  } catch (error) {
    console.error(`Error removing admin:`, error.message);
  }
})();

💻 Get admins

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.admin.getAdmins();
    console.log(response)
  } catch (error) {
    console.error(`Error listing admins:`, error.message);
  }
})();

💻 User creation

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
    try {
        const userData = {
            status: "active",
            username: "JohnDoe",
            note: "Created using marzban api",
            proxies: {
                vmess: {}
            },
            data_limit: 0,
            expire: 0,
            data_limit_reset_strategy: "no_reset",
            inbounds: {
                vmess: ["VMess TCP"]
            }
        };

        const response = await marzban.user.addUser(userData);
        console.log('User added successfully:', response);
    } catch (error) {
        console.error('Error adding user:', error.message);
    }
})();

💻 Fetching user information

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const response = await marzban.user.getUser(username);
    console.log('User information retrieved successfully:', response);
  } catch (error) {
    console.error('Error retrieving user information:', error.message);
  }
})();

💻 Modifying user

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const userData = {
      proxies: {
        vmess: {
          id: '35e4e39c-7d5c-4f4b-8b71-558e4f37ff53'
        },
        vless: {}
      },
      inbounds: {
        vmess: ['VMess TCP', 'VMess Websocket'],
        vless: ['VLESS TCP REALITY', 'VLESS GRPC REALITY']
      },
      expire: 0,
      data_limit: 0,
      data_limit_reset_strategy: 'no_reset',
      status: 'active',
      note: 'Updated note',
      on_hold_timeout: '2023-11-03T20:30:00',
      on_hold_expire_duration: 0
    };

    const response = await marzban.user.modifyUser(username, userData);
    console.log('User modified successfully:', response);
  } catch (error) {
    console.error('Error modifying user:', error.message);
  }
})();

💻 Deleting user

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const response = await marzban.user.removeUser(username);
    console.log('User removed successfully:', response);
  } catch (error) {
    console.error('Error removing user:', error.message);
  }
})();

💻 Get user usage

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const response = await marzban.user.getUserUsage(username);
    console.log(response)
  } catch (error) {
    console.error(`Error getting user's usage:`, error.message);
  }
})();

💻 Reset User Data Usage

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const response = await marzban.user.resetUserDataUsage(username);
    console.log(response)
  } catch (error) {
    console.error(`Error resetting user's usage:`, error.message);
  }
})();

💻 Revoke User Subscription

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const username = 'user1234'; 
    const response = await marzban.user.revokeUserSubscription(username);
    console.log(response)
  } catch (error) {
    console.error(`Error revoking user's subscription:`, error.message);
  }
})();

💻 Get users

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.user.getUsers();
    console.log(response)
  } catch (error) {
    console.error(`Error listing all users:`, error.message);
  }
})();

💻 Reset all users usage

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.user.resetUsersDataUsage();
    console.log(response)
  } catch (error) {
    console.error(`Error resetting usage for all users:`, error.message);
  }
})();

💻 Set user owner

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_user = "chilluser";
    const target_admin = "chilladmin";
    const response = await marzban.user.setUserOwner(target_user, target_admin);
    console.log(response)
  } catch (error) {
    console.error(`Error setting ${target_admin} as admin parent for ${target_user}:`, error.message);
  }
})();

💻 Get expired users

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.user.getExpiredUsers();
    console.log(response)
  } catch (error) {
    console.error(`Error listing expired users:`, error.message);
  }
})();

💻 Delete expired users

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.user.deleteExpiredUsers();
    console.log(response)
  } catch (error) {
    console.error(`Error deleting expired users:`, error.message);
  }
})();

💻 Get user subscription

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const token = "COOLTOKENINSERTEDHERE";
    const response = await marzban.user.getUserSubscription(token);
    console.log(response)
  } catch (error) {
    console.error(`Error getting user subscription:`, error.message);
  }
})();

💻 Get user subscription information

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const token = "COOLTOKENINSERTEDHERE";
    const response = await marzban.user.getUserSubscriptionInfo(token);
    console.log(response)
  } catch (error) {
    console.error(`Error getting user subscription information:`, error.message);
  }
})();

💻 Get user subscription usage

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const token = "COOLTOKENINSERTEDHERE";
    const response = await marzban.user.getUserSubscriptionUsage(token);
    console.log(response)
  } catch (error) {
    console.error(`Error getting user subscription usage:`, error.message);
  }
})();

💻 Get user subscription with client type

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const token = "COOLTOKENINSERTEDHERE";
    const client = "clash"; 
    const response = await marzban.user.getUserSubscriptionWithClientType(token, client);
    console.log(response)
  } catch (error) {
    console.error(`Error getting user subscription with client type:`, error.message);
  }
})();

💻 Get user templates

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const response = await marzban.templates.getUserTemplates();
    console.log(response)
  } catch (error) {
    console.error(`Error listing user templates:`, error.message);
  }
})();

💻 Add user template

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const template_data = {
     "name": "cool_template",
      "inbounds": {
       "vmess": [
          "VMESS_INBOUND"
       ],
        "vless": [
          "VLESS_INBOUND"
       ]
     },
      "data_limit": 0,
      "expire_duration": 0
    }
    const response = await marzban.templates.addUserTemplate(template_data);
    console.log(response)
  } catch (error) {
    console.error(`Error creating template:`, error.message);
  }
})();

💻 Get user template by id

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const template_id = "1";
    const response = await marzban.templates.getUserTemplateById(template_id);
    console.log(response)
  } catch (error) {
    console.error(`Error getting template by id:`, error.message);
  }
})();

💻 Modify user template

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_template_id = "1";
    const template_data = {
      "name": "cool_template_2",
      "inbounds": {
       "vmess": [
          "VMESS_INBOUND"
       ]
     },
     "data_limit": 0,
      "expire_duration": 0
    }
    const response = await marzban.templates.modifyUserTemplate(target_template_id, template_data);
    console.log(response)
  } catch (error) {
    console.error(`Error modifying template:`, error.message);
  }
})();

💻 Deleting user template

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_template_id = "1";
    const response = await marzban.templates.removeUserTemplate(target_template_id);
    console.log(response)
  } catch (error) {
    console.error(`Error deleting template:`, error.message);
  }
})();

💻 Get node settings

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const node_settings = await marzban.node.getNodeSettings();
    console.log(node_settings)
  } catch (error) {
    console.error(`Error getting node settings:`, error.message);
  }
})();

💻 Add node

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const node_data = {
      "name": "Germany node",
      "address": "192.168.1.1",
      "port": 62050,
      "api_port": 62051,
      "add_as_new_host": false,
      "usage_coefficient": 1
    }
    const node = await marzban.node.addNode(nodeData);
    console.log(node);
  } catch (error) {
    console.error(`Error while adding a new node:`, error.message);
  }
})();

💻 Get node

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_node_id = "1";
    const node = await marzban.node.getNode(target_node_id);
    console.log(node);
  } catch (error) {
    console.error(`Error while getting a node:`, error.message);
  }
})();

💻 Modify node

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_node_id = "1";
    const new_node_data = {
      "name": "Germany Node Modified",
      "address": "192.168.1.1",
      "port": 62050,
      "api_port": 62051,
      "status": "disabled",
      "usage_coefficient": 1
    }
    const node = await marzban.node.modifyNode(target_node_id, new_node_data);
    console.log(node);
  } catch (error) {
    console.error(`Error while modifying a node:`, error.message);
  }
})();

💻 Remove node

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_node_id = "1";
    const node = await marzban.node.removeNode(target_node_id);
    console.log(node);
  } catch (error) {
    console.error(`Error while removing a node:`, error.message);
  }
})();

💻 Get nodes

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const nodes = await marzban.node.getNodes();
    console.log(nodes);
  } catch (error) {
    console.error(`Error while retrieving nodes:`, error.message);
  }
})();

💻 Reconnect node

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const target_node_id = "1";
    const node = await marzban.node.reconnectNode(target_node_id);
    console.log(node);
  } catch (error) {
    console.error(`Error while retrieving nodes:`, error.message);
  }
})();

💻 Get nodes usage

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const nodes_usage = await marzban.node.getNodesUsage();
    console.log(nodes_usage);
  } catch (error) {
    console.error(`Error while retrieving nodes usages:`, error.message);
  }
})();

💻 Get system stats

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const system_stats = await marzban.system.getSystemStats();
    console.log(system_stats);
  } catch (error) {
    console.error(`Error while getting system stats:`, error.message);
  }
})();

💻 Get inbounds

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const inbounds = await marzban.system.getInbounds();
    console.log(inbounds);
  } catch (error) {
    console.error(`Error while getting inbounds:`, error.message);
  }
})();

💻 Get hosts

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const hosts = await marzban.system.getHosts();
    console.log(hosts);
  } catch (error) {
    console.error(`Error while getting hosts:`, error.message);
  }
})();

💻 Modify hosts

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const host_data = {
       "VLESS_CDN_INBOUND": [
         {
            "remark": "Germany Node",
            "address": "192.168.1.1",
            "port": 8585,
            "sni": "",
            "host": "",
            "path": "",
            "security": "inbound_default",
            "alpn": "",
            "fingerprint": "",
            "allowinsecure": true,
            "is_disabled": true,
            "mux_enable": true,
            "fragment_setting": "",
            "noise_setting": "",
            "random_user_agent": true
         }
       ]
     };
    const hosts = marzban.system.modifyHosts(host_data);
    console.log(hosts);
  } catch (error) {
    console.error(`Error while modifying hosts:`, error.message);
  }
})();

💻 Get core stats

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const core_stats = marzban.core.getCoreStats();
    console.log(core_stats);
  } catch (error) {
    console.error(`Error while getting core stats:`, error.message);
  }
})();

💻 Restart core

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const restart_core = marzban.core.restartCore();
    console.log(restart_core);
  } catch (error) {
    console.error(`Error while restarting core:`, error.message);
  }
})();

💻 Get core config

const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const core_config = marzban.core.getCoreConfig();
    console.log(core_config);
  } catch (error) {
    console.error(`Error while getting core config:`, error.message);
  }
})();

💻 Modify core config

const fs = require('fs');
const MarzbanAPI = require('@maniwrld/marzjs');

const marzban = MarzbanAPI({
  domain: 'example.com',
  port: 8080,
  ssl: true,
  username: 'admin',
  password: 'securepassword'
});

(async () => {
  try {
    const xrayConfigPath = './xray_config.json';
    if (!fs.existsSync(xrayConfigPath)) {
      throw new Error('xray_config.json file not found');
    }

    const xrayConfigContent = fs.readFileSync(xrayConfigPath, 'utf8');
    const xrayConfig = JSON.parse(xrayConfigContent);

    const coreConfig = await marzban.core.modifyCoreConfig(xrayConfig);
    console.log('Core configuration updated successfully:', coreConfig);
  } catch (error) {
    console.error(`Error while modifying core config:`, error.message);
  }
})();

🛡 Error Handling

The library provides comprehensive error handling:

  • Automatic token refresh
  • Detailed error messages
  • Joi input validation

🗺️ Roadmap & Community Forks

📍 Future Development Roadmap

  • <input disabled="" type="checkbox"> Add TypeScript type definitions
  • <input disabled="" type="checkbox"> Implement comprehensive unit and integration tests
  • <input disabled="" type="checkbox"> Enhance WebSocket logging with more filtering options
  • <input disabled="" type="checkbox"> Create detailed documentation with more comprehensive examples
  • <input disabled="" type="checkbox"> Add support for more advanced authentication methods
  • <input disabled="" type="checkbox"> Implement rate limiting and advanced retry strategies
  • <input disabled="" type="checkbox"> Develop a CLI tool for MarzJS

🌐 Supporting Marzban Forks

MarzJS aims to maintain compatibility with various Marzban forks to provide a versatile API client:

1. Marzneshin

2. MarzGosha

Note: Compatibility with these forks is an active area of development. Community feedback and contributions are welcome!

📝 Requirements

  • Node.js 12.0.0 or higher
  • Dependencies: axios, ws, qs, joi

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0)

🏷️ Versioning

Current Version: 1.0.9
We use SemVer for versioning.

💌 Support

Encountering issues? Open an issue on GitHub.

⭐ Support the Project

If you find MarzJS useful, please give it a star on GitHub! It helps us stay motivated and grow the project.