Innovenergy_trunk/csharp/App/OpenVpnCertificatesServer/newToken.sh

32 lines
978 B
Bash
Raw Normal View History

2023-03-23 14:57:51 +00:00
#!/bin/bash
## create a new VRM access token
## USAGE: ./newToken.sh -u Username -p Password -n UniqueTokenName
2023-03-23 14:57:51 +00:00
while getopts u:p:n: flag
2023-03-23 14:57:51 +00:00
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
n) name=${OPTARG};;
2023-03-23 14:57:51 +00:00
esac
done
response=$(curl --request POST \
2023-03-23 14:57:51 +00:00
--url https://vrmapi.victronenergy.com/v2/auth/login \
--header 'Content-Type: application/json' \
--data '{"username":"'$username'","password":"'$password'","sms_token":null,"remember_me":false,"language":""}')
echo -n '{"bearer' > token.json
token=$(echo $response | jq ".token")
uid=$(echo $response | jq ".idUser")
echo -n ${response:7:-1} >> token.json
response2=$(curl --request POST \
--url https://vrmapi.victronenergy.com/v2/users/$uid/accesstokens/create \
--header 'Content-Type: application/json' \
--header 'x-authorization: Bearer '${token:1:-1} \
--data '{"name":"'$name'"}')
echo -n , >> token.json
echo -n ${response2:1} >> token.json