Marzban - получение токена по API
Материал из Все о VPN, прокси и свободном интернете
Marzban - получение токена по API
Получение токена curl -s -X 'POST' \ 'http://VPS_IP:PORT/api/admin/token' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=&username=USER_HERE&password=PASS_HERE&scope=&client_id=&client_secret=' USER_HERE - заменить на свой PASS_HERE - заменить на свой
Парсинг через jq:
curl -s -X 'POST' \ 'http://VPS_IP:PORT/api/admin/token' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=&username=USER_HERE&password=PASS_HERE&scope=&client_id=&client_secret=' | jq
Вывести только токен (access_token):
Парсинг через python3: curl -s -X 'POST' \ 'http://VPS_IP:PORT/api/admin/token' \ -H 'accept: application/json' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=&username=USER_HERE&password=PASS_HERE&scope=&client_id=&client_secret=' | python3 -c "import sys, json; print(json.load(sys.stdin) 'access_token'])"
Другой вариант через python3 (curl > 8.3.0):
curl -X 'POST' --variable passmarban=$PASS1111 'http://VPS_IP:PORT/api/admin/token' -H 'accept: application/json' -H 'Content-Type: application/x-www-form-urlencoded' -d "username=admin1" --expand-data "password={{passmarban}}" | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])"
Links:
https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools