NeuroAgent

How to Get User CLI Key in Marzban: Fixing the Error

Fixing the issue with getting user key in Marzban CLI. Learn the correct commands, version checking, and resolving the 'reverse' error.

Question

How to get a user key through CLI in Marzban?

When trying to get a Marzban user key through CLI with the command:

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

I get a JSON file structure and an error:

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

The user key itself is not being retrieved.

The marzban update command supposedly updates the version, but doesn’t specify to which version it’s updating. The marzban status command only outputs “running” without showing the Marzban version. The core version is 25.8.3.

How do I properly get a user key through CLI in Marzban and how do I determine the current Marzban version?

NeuroAgent

Getting User Keys Through CLI in Marzban

To get a user key through CLI in Marzban, use the correct command and configure the necessary parameters. The error with the missing ‘reverse’ argument is usually related to version incompatibilities or incorrect configuration.

To get a user key, execute the command:

marzban cli subscription get-config -u username -f v2ray

To determine the current Marzban version, execute:

marzban --version

If the --version command doesn’t work, check the installation files or execute:

## Contents {#contents}
- [Basic Marzban CLI Commands for Getting User Keys](#basic-marzban-cli-commands-for-getting-user-keys)
- [Solving the 'reverse' Argument Error](#solving-the-reverse-argument-error)
- [Determining the Marzban Version](#determining-the-marzban-version)
- [Additional Parameters and Formats](#additional-parameters-and-formats)
- [Troubleshooting and Recommendations](#troubleshooting-and-recommendations)
- [Usage Examples](#usage-examples)

## Basic Marzban CLI Commands for Getting User Keys {#basic-marzban-cli-commands-for-getting-user-keys}

To get a user key through CLI in Marzban, you should use the `get-config` command in the `subscription` section. The basic syntax of the command is:

marzban cli subscription get-config -u [username] -f [format]

Where:
- `-u` or `--username` - username
- `-f` or `--format` - output format (v2ray, clash)

Basic command example:

marzban cli subscription get-config -u myuser -f v2ray

This command will output the user configuration in the specified format, which contains all the necessary information for connection, including keys and proxy settings.

## Solving the 'reverse' Argument Error {#solving-the-reverse-argument-error}

The `TypeError: generate_subscription() missing 1 required positional argument: 'reverse'` error usually occurs due to:

1. **Version incompatibility** - in newer versions of Marzban, the structure of the subscription generation function arguments has changed
2. **Missing required environment parameters** - some environment variables must be properly configured

To solve this problem:

1. **Update Marzban to the latest version**:
```bash
sudo marzban update
  1. Check and configure environment variables. Make sure that in the /opt/marzban/.env file, the necessary variables are set, especially:

    • XRAY_SUBSCRIPTION_URL_PREFIX - URL prefix for subscriptions
    • SUBSCRIPTION_DOMAIN - domain for subscriptions
  2. Use an alternative approach with saving to a file:

bash
marzban cli subscription get-config -u myuser -f v2ray -o config.json
  1. If the problem persists, try using the command to get a subscription link instead of the direct configuration:
bash
marzban cli subscription get-link -u myuser

Determining the Marzban Version

Since the marzban status command doesn’t show the version, and marzban update doesn’t specify the target version, use the following methods:

  1. Version command (if available):
bash
marzban --version
  1. Check via pip (if installed via pip):
bash
pip show marzban
  1. Check installation files:
bash
ls -la /opt/marzban/
cat /opt/marzban/requirements.txt  # may contain version
  1. Check via git (if installed from source):
bash
cd /opt/marzban
git log --oneline -1
  1. Check configuration:
bash
cat /opt/marzban/.env | grep -E "(VERSION|TAG)"

The Xray core version (25.8.3) is specified separately from the Marzban GUI version. For full compatibility, make sure the Marzban version matches your Xray core version.

Additional Parameters and Formats

Marzban CLI supports various output formats and additional parameters:

Supported formats:

  • v2ray - format for V2Ray clients
  • clash - format for Clash clients
  • base64 - encoding in Base64 (added via --base64)

Command with saving to a file:

bash
marzban cli subscription get-config -u myuser -f v2ray -o v2ray_config.json

Command with Base64 encoding:

bash
marzban cli subscription get-config -u myuser -f v2ray --base64

View all available user proxies:

bash
marzban cli subscription get-proxies -u myuser

Get subscription link:

bash
marzban cli subscription get-link -u myuser

Important: For the get-link command to work, you need to set the XRAY_SUBSCRIPTION_URL_PREFIX environment variable. Add it to the /opt/marzban/.env file:

XRAY_SUBSCRIPTION_URL_PREFIX=https://sub.yourdomain.com/sub/

Troubleshooting and Recommendations

Common problems and solutions:

  1. “missing 1 required positional argument: ‘reverse’” error:

    • Update Marzban to the latest version
    • Check compatibility between Marzban and Xray core versions
    • Make sure all environment variables are properly configured
  2. Empty output or authentication error:

    • Check user access rights
    • Make sure the user exists
    • Check connection to the Marzban API
  3. Incorrect output format:

    • Make sure the selected format is supported by your client
    • Check output encoding

Update recommendations:

  1. Run the update:
bash
sudo marzban update
  1. Restart the service:
bash
sudo marzban restart
  1. Check status:
bash
sudo marzban status
  1. Check CLI functionality:
bash
marzban cli --help

Usage Examples

Example 1: Getting user configuration in V2Ray format:

bash
marzban cli subscription get-config -u testuser -f v2ray

The output will contain a JSON configuration with proxy settings.

Example 2: Saving configuration to a file:

bash
marzban cli subscription get-config -u testuser -f v2ray -o ~/v2ray_config.json

Example 3: Getting configuration in Clash format:

bash
marzban cli subscription get-config -u testuser -f clash

Example 4: Getting subscription in Base64 format:

bash
marzban cli subscription get-config -u testuser -f v2ray --base64

Example 5: Checking if a user exists:

bash
marzban cli user list | grep testuser

If the user is not found, first create them through the web interface or CLI:

bash
marzban cli user create --username testuser --data-limit 100 --expire 30

Sources

  1. Marzban CLI Official Documentation
  2. Neonode.cc Marzban CLI Guide
  3. GitHub Marzban CLI Source Code
  4. Marzban Configuration Documentation
  5. Marzban Subscription Documentation
  6. Marzban GitHub Repository
  7. Marzban Changelog

Conclusion

  • To get a user key through CLI, use the command marzban cli subscription get-config -u [username] -f [format]
  • The error with the ‘reverse’ argument is usually related to version incompatibilities - update Marzban to the latest version
  • To determine the Marzban version, try the commands marzban --version, pip show marzban, or check installation files
  • Configure the necessary environment variables, especially XRAY_SUBSCRIPTION_URL_PREFIX for working with subscriptions
  • Save configurations to files using the -o [file] parameter for convenience
  • Check compatibility between Marzban and Xray core versions for stable operation

If problems persist, refer to the official Marzban documentation or community for help with your specific version and configuration.