Hi all,
I’m the API Tech Docs Writer here at Automox, and I wanted to introduce myself and let you know I’m here for any API-related questions you might have. To kick things off, here’s a quick Bash script I created.
This script will allow you to invite a list of users and assign roles from a CSV to a given Automox organization. This is particularly useful in cases where you might have a number of users that need to be added, like when onboarding new employees.
This script is org specific, so if you have multiple orgs, you will need to create a separate CSV for each org, containing the users to be added to that org and their roles. You would then need to run the script against each org, using the specific org id and api key.
Copy the script, and save it as
adduser_csv.sh
in the directory of your choice. Usechmod u+x adduser_csv.sh
to change the permissions of the file to make it executable.
Create a CSV file containing 2 columns. The headers for these columns should be
Email
andRBAC_Role
. Add the email addresses of the users you want to add to theEmail
column, and the role for each of them in theRBAC_Role
column. Save this file to the same directory where you have the script stored.
- Acceptable values for
RBAC_Role
are as follows:
- Full Administrator
- Patch Administrator
- Billing Administrator
- Read Only
Note: When creating your CSV file, be sure that the file conforms to the following specifications (You can check this by opening the file in a text editor)
- Your CSV should contain a header. This script is set to start from row 2, so it will ignore the header. If your CSV does not contain a header, it will skip the user on the first line.
- Each line should end with a LF (not CR or CRLF).
- Fields should be delimited by a comma, and text should not be quoted.
- Column 1 should contain valid email addresses for the users you would like to invite.
- Column 2 should contain an acceptable value for
RBAC_Role
for each user.
- Acceptable values for
Open a terminal, change to the directory where you’ve saved the script and where the CSV file is located, and run the script by entering
./adduser_csv.sh
. The script will prompt you for the name of your CSV file, your API key, and the organization ID.
Note: You must use the terminal to run this script.
When successful, this script will return an object for each invited user, and an HTTP code, in this case, a 200.
If there is invalid data (an invalid email or an unacceptable value for RBAC_Role
), the script will return which row contains invalid data and continue acting on the remaining rows.
Example:
{"inviter_firstname":"Laurie","inviter_lastname":"Laidley","email":"test@example.com","org_name":"My Automox Test Org"}200
Script:
#!/bin/bash
read -r -p "Please enter your organization ID:" org < /dev/tty
read -r -p "Please enter the name of your CSV file:" filename < /dev/tty
read -r -s -p "Please enter your API key:" apiKey < /dev/tty
printf "\n"
i=1
declare -a rbac_array=(
'Full Administrator'
'Patch Administrator'
'Billing Administrator'
'Read Only'
)
pattern="^ta-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.}a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(~a-z0-9](aa-z0-9-]*-a-z0-9])?\.)+9a-z0-9](aa-z0-9-]*-a-z0-9])?\$"
while IFS="," read -r email rbac_role; do
if
"$email" =~ $pattern ]]; then
valid_email=1
else
valid_email=0
fi
for value in "${rbac_arraya@]}"; do
if "$rbac_role" = "$value" ]]; then
valid_role=1
break
else
valid_role=0
fi
done
if
${valid_email} -eq 1 ]] && p; ${valid_role} -eq 1 ]]; then
curl -s -o /dev/tty \
-w "%{http_code}" \
--location \
--request POST "https://console.automox.com/inviteUser?o=${org}&email=${email}&rbac_role=${rbac_role}" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${apiKey}"
printf "\n"
else
echo "CSV row ${i} contains invalid data!"
fi
done <<< "$(tail -n +2 "${filename}")"