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

Using the API to add a new user (API Basic AUTH)

The shell cript 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 must be admin
user='admin'
pword='admin_users_pwd_here'

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

# New File User - the users password is required
# echo ""
# echo "=================================================="
# echo curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -u "$user:$pword" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","password":"'"$newuserpwd"'","auth":"File","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'
# echo "=================================================="
# curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -u "$user:$pword" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","password":"'"$newuserpwd"'","auth":"File","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'
# ============================================================



# A New RADIUS User - A password is not required
echo ""
echo "=================================================="
echo curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -u "$user:$pword" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","auth":"RADIUS","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'
echo "=================================================="

curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json" -u "$user:$pword" https://${server}/${query} -d '{"data":[{"name":"'"$newuser"'","auth":"RADIUS","email":"'"$newusermail"'","api":"r","tz":"Europe/London"}]}'

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