Skip to content

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

Notifications You must be signed in to change notification settings

maniwrld/marzjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 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

  • Add TypeScript type definitions
  • Implement comprehensive unit and integration tests
  • Enhance WebSocket logging with more filtering options
  • Create detailed documentation with more comprehensive examples
  • Add support for more advanced authentication methods
  • Implement rate limiting and advanced retry strategies
  • 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.7
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.

Releases

No releases published

Packages

No packages published