NeuroAgent

How to Get User Key via Marzban CLI

Solution for getting user key via Marzban CLI. Step-by-step guide to fixing the 'reverse' argument error and alternative methods for working with Marzban CLI.

Question

How to get a user key through CLI in Marzban?

I need to get a Marzban user key specifically through the command line interface (CLI). When I run the command:

marzban cli subscription get-config -u user -f v2ray --base64

I get a JSON file structure, but an error also occurs:

TypeError: generate_subscription() missing 1 required positional argument: 'reverse'

The user key itself is not obtained.

The marzban update command supposedly updates the version, but I don’t know to which version. The marzban status command doesn’t output any information except the “running” status. The core version is 25.8.3.

How do I properly get a user key through CLI in Marzban and how do I solve the error with the ‘reverse’ argument?

NeuroAgent

Getting User Keys via CLI in Marzban: Complete Guide

To get a user key via CLI in Marzban, you need to use the correct command syntax and resolve the issue with the ‘reverse’ argument. Here’s a detailed solution:

Table of Contents

Correct command for getting user key

The main command to get a user’s configuration through Marzban CLI:

bash
marzban cli subscription get-config -u <username> -f [v2ray|clash] --base64

Where:

  • <username> - username in your Marzban system
  • -f v2ray - v2ray format (clash is also supported)
  • --base64 - output in base64 format

If you want to save the result to a file:

bash
marzban cli subscription get-config -u <username> -f v2ray -o config.json

Important: Make sure you have administrator rights to execute this command and that the user exists in the Marzban system.

Solving the ‘reverse’ argument error

The error TypeError: generate_subscription() missing 1 required positional argument: 'reverse' occurs due to changes in the Marzban API. Here are several ways to solve it:

1. Update Marzban to the latest version

This error often occurs in older versions. Update Marzban:

bash
pip install --upgrade marzban

2. Using environment variables

Add to your .env file or set through environment variable:

bash
export USE_CUSTOM_JSON_DEFAULT=True

3. Check configuration

Make sure your configuration file is set up correctly. According to Marzban documentation, add to .env:

bash
# For v2rayNG
USE_CUSTOM_JSON_FOR_V2RAYNG=True
# For other clients
USE_CUSTOM_JSON_FOR_V2RAYN=False
USE_CUSTOM_JSON_FOR_STREISAND=False

4. Alternative command syntax

Try using an alternative command format:

bash
marzban subscription get-config -u <username> -f v2ray --base64

5. If the problem persists

If the error remains, it might be related to a specific version. Check issue #886 on GitHub where similar v2ray configuration problems are discussed.

Checking Marzban version

To check the Marzban and core version, use the following commands:

Check Marzban CLI version:

bash
marzban --version

Check status and version:

bash
marzban status

Core version information:

The core version (25.8.3) is indicated during installation. To check the installed version:

bash
xray version

Check via pip:

bash
pip show marzban

Alternative methods for getting keys

If CLI doesn’t work, you can get the user key through other methods:

1. Through Marzban web interface

  1. Go to the Marzban web panel
  2. Navigate to the “Users” section
  3. Find the desired user
  4. Copy the subscription link

2. Through Marzban API

Use the API to get the configuration:

bash
curl -X GET "http://localhost:8000/api/user/<username>/subscription/v2ray" \
-H "accept: application/json" \
-H "Authorization: Bearer <your_token>"

3. Through Telegram bot

If you have a Telegram bot configured for Marzban, you can get the key through the bot.

Troubleshooting other problems

1. Permission issues

If CLI commands don’t work, check user permissions:

bash
sudo -u <user_marzban_is_running_as> marzban cli subscription get-config -u test -f v2ray

2. Configuration issues

Restart Marzban after making configuration changes:

bash
marzban restart

3. Error logging

For more detailed error analysis, enable verbose logging:

bash
marzban cli subscription get-config -u test -f v2ray --verbose

4. Check dependencies

Make sure all required dependencies are installed:

bash
pip install -r requirements.txt

Sources

  1. Marzban CLI Documentation - Official
  2. Marzban Configuration Guide
  3. GitHub - Marzban CLI Commands
  4. Issue #886 - QUIC bugs and subscription problems
  5. Marzban Changelog - Version 0.7.0 fixes
  6. Neonode.cc - Marzban CLI Tutorial

Conclusion

  1. Main command for getting a user key: marzban cli subscription get-config -u <username> -f v2ray --base64
  2. ‘reverse’ argument error is usually resolved by updating Marzban or setting environment variables
  3. Version check through marzban --version and pip show marzban
  4. Alternative methods include web interface and API for getting keys
  5. Error prevention - regular updates and configuration checks

If the problem persists, it’s recommended to check GitHub issues or contact the Marzban community for more specific help regarding your version and configuration.