The fields to "add" function to add accounts using API are the following:
=================================================
key: Key authorized by Api administrator
action: add
domain: main domain associated with the account
user: username to create
pass: Password for the account
email: Email Address of the account owner
package: Create account with package
inode: number of inodes allowed
limit_nofile: limit_nofile
server_ips: server_ips
=================================================
Ps:
1) Is not possible to preserve Ids from other server with API. Only hardcoded is possible, although not recommended.
2) you don't have passwords in your data file, but passwords are mandatory to the API.
So, you can add a field to fulfil the password field, or change it to your taste.
3) max lenght of username field is assumed 8 characters lenth, of valid characters to unix usernames.
So, suppose you have your data accounts in a file name 'dataaccounts.csv' in current directory.
Save and run the following script:
#!/bin/sh
# Change the following variables
value_key="[YOUR KEY HERE]"
default_password="[DEFAULT PASSWORD]"
password="[PASSWORD]"
your_server="[YOUR-SERVER]" # IP address or domain
while IFS="," read id username domain ip_address email setup_date package backup; do
status=$(curl --data "key=${value_key}" \
--data "action=add" \
--data "domain=${domain}" \
--data "user=${username}" \
--data "pass=${default_password}" \
--data "email=${email}" \
--data "package=${package}" \
--data "inode=0" \
--data "limit_nofile=0" \
--data "server_ips=${ip_address}" \
https://${your_server}:2304/v1/account)
if [[ ${status} -eq 28 ]]; then
echo "... ... Timeout accessing URL: https://${your_server}:2304/v1/account ... !!!"
echo "Timeout accessing URL https://${your_server}:2304/v1/account: More than $timeout seconds trying to access." | \
elif [[ ${status} -eq 6 ]]; then
echo "... ... Error accessing URL: https://${your_server}:2304/v1/account ... !!!"
echo "Error accessing URL https://${your_server}:2304/v1/account: The domain host could not be resolved." | \
elif [[ ${status} -eq 51 ]]; then
echo "... ... Error accessing URL: https://${your_server}:2304/v1/account ... !!!"
error = "Error accessing URL https://${your_server}:2304/v1/account: Could not communicate securely with server:"
error = "${error} The requested domain does not match the server's certificate."
echo ${error}
elif [[ ${status} -gt 0 ]]; then
error = "Error code ${status} has been returned"
echo "${error}"
fi
done < dataaccounts.csv
This script was written in bash, but you can write it too in php, as suggested in CWP API manager.