32 lines
978 B
Bash
Executable File
32 lines
978 B
Bash
Executable File
#!/bin/bash
|
|
## create a new VRM access token
|
|
## USAGE: ./newToken.sh -u Username -p Password -n UniqueTokenName
|
|
|
|
|
|
while getopts u:p:n: flag
|
|
do
|
|
case "${flag}" in
|
|
u) username=${OPTARG};;
|
|
p) password=${OPTARG};;
|
|
n) name=${OPTARG};;
|
|
esac
|
|
done
|
|
|
|
response=$(curl --request POST \
|
|
--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 |