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?
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
-
Check and configure environment variables. Make sure that in the
/opt/marzban/.envfile, the necessary variables are set, especially:XRAY_SUBSCRIPTION_URL_PREFIX- URL prefix for subscriptionsSUBSCRIPTION_DOMAIN- domain for subscriptions
-
Use an alternative approach with saving to a file:
marzban cli subscription get-config -u myuser -f v2ray -o config.json
- If the problem persists, try using the command to get a subscription link instead of the direct configuration:
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:
- Version command (if available):
marzban --version
- Check via pip (if installed via pip):
pip show marzban
- Check installation files:
ls -la /opt/marzban/
cat /opt/marzban/requirements.txt # may contain version
- Check via git (if installed from source):
cd /opt/marzban
git log --oneline -1
- Check configuration:
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 clientsclash- format for Clash clientsbase64- encoding in Base64 (added via--base64)
Command with saving to a file:
marzban cli subscription get-config -u myuser -f v2ray -o v2ray_config.json
Command with Base64 encoding:
marzban cli subscription get-config -u myuser -f v2ray --base64
View all available user proxies:
marzban cli subscription get-proxies -u myuser
Get subscription link:
marzban cli subscription get-link -u myuser
Important: For the
get-linkcommand to work, you need to set theXRAY_SUBSCRIPTION_URL_PREFIXenvironment variable. Add it to the/opt/marzban/.envfile:XRAY_SUBSCRIPTION_URL_PREFIX=https://sub.yourdomain.com/sub/
Troubleshooting and Recommendations
Common problems and solutions:
-
“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
-
Empty output or authentication error:
- Check user access rights
- Make sure the user exists
- Check connection to the Marzban API
-
Incorrect output format:
- Make sure the selected format is supported by your client
- Check output encoding
Update recommendations:
- Run the update:
sudo marzban update
- Restart the service:
sudo marzban restart
- Check status:
sudo marzban status
- Check CLI functionality:
marzban cli --help
Usage Examples
Example 1: Getting user configuration in V2Ray format:
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:
marzban cli subscription get-config -u testuser -f v2ray -o ~/v2ray_config.json
Example 3: Getting configuration in Clash format:
marzban cli subscription get-config -u testuser -f clash
Example 4: Getting subscription in Base64 format:
marzban cli subscription get-config -u testuser -f v2ray --base64
Example 5: Checking if a user exists:
marzban cli user list | grep testuser
If the user is not found, first create them through the web interface or CLI:
marzban cli user create --username testuser --data-limit 100 --expire 30
Sources
- Marzban CLI Official Documentation
- Neonode.cc Marzban CLI Guide
- GitHub Marzban CLI Source Code
- Marzban Configuration Documentation
- Marzban Subscription Documentation
- Marzban GitHub Repository
- 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_PREFIXfor 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.