Skip to content
  • There are no suggestions because the search field is empty.

Using the API to add a new user (TOKEN based AUTH)

The shell script can be used as a basis to add a File or RADIUS type user with a API calls. The variables could be extended to import from a CSV file

#!/usr/bin/sh

# Statseeker Server IP
server='xxx.xxx.xxx.xxx'

# The User to be added - need to work out how to parse in users and user email from a CSV file
newuser=whoever1234
newusermail=whoever@test.com
newuserpwd=whatever
# The User to be added - this will need to be worked out

# The Statseeker API User running the command
user='admin'
pword='admin_users_pwd_here'

# Set the Endpoint
query='api/v2.1/user'
# The User to be added - this will need to be worked out

# Get the Access Token
ACCESS_TOKEN=$(curl -k -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "user=${user}&password=${pword}" "https://${server}/ss-auth" | jq -r '.access_token')
echo ""
echo "=================================================="
echo "$ACCESS_TOKEN"
echo "=================================================="
echo ""

# Set the Endpoint
query='api/v2.1/user'

# Set the Target
queryFile="-d '{"data":[{"name":"'"$newuser"'","password":"'"$newuserpwd"'","auth":"File","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'"
queryRadius= "-d '{"data":[{"name":"'"$newuser"'","auth":"RADIUS","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'"

# =============================================================
# For a New User that uses the local file type File - a password is required in the data field
# unhash the one of the curl commands below and related echo to see what it is doing

# echo "=================================================="
# echo curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} ${queryFile]
# curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} ${queryFile]
# curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","password":"'"$newuserpwd"'","auth":"File","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'"
# echo "=================================================="


# For a New RADIUS User - A password is not required

# =============================================================
# Add New RADIUS User - password is required in the data field
# unhash the echo and one of the curl commands below

# echo "=================================================="
# echo curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} ${queryRadius]
# curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} ${queryRadius]
# curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","auth":"RADIUS","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'"
# echo "=================================================="


# Check User Added
curl -k -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" "https://${server}/${query}?fields=name,email"  | grep -o '"name":"[^"]\+"'