Hi,
Is there a way to add users in bulk? Perhaps through a .csv or .txt
file and thus avoid the user having to log in to register for the
first time in the application.
Is this possible?
You could use a bash script using curl to call the API for that:
Create a .CSV file in my case I used |demo.csv| where every line
contains |username,organization,full name,timezone| e.g.:
|peter,Homeland Security,Peter Hacker,Europe/Berlin sepp,DOD,Sepp
Intruder,America/Chicago jeff,FBI,Jeff Johnson,Australia/Adelaide |
then modify the following lines:
|adminuser='youradminuser' adminpass='youradminpassword'
baseurl='https://<your guacamole url>' |
in the following script |demo.bash| within the same folder as |demo.csv|
|#!/bin/bash adminuser='youradminuser' adminpass='youradminpassword'
baseurl='https://<your guacamole url>' csvfile='./demo.csv' # get auth
token result=$(curl -s -d "username=$adminuser&password=$adminpass" -X
POST "$baseurl/api/tokens") token=$(echo $result | jq -r .authToken)
datasource=$(echo $result | jq -r .dataSource) echo "$token $datasource"
while IFS=, read -r username organization fullname timezone do echo
"$username $organization $fullname $timezone" # create new user
result=$(curl -s -H 'Accept: application/json' -H 'Content-Type:
application/json' -X POST
"$baseurl/api/session/data/$datasource/users?token=$token" --data-binary
@- << EOF { "username": "$username", "attributes": { "disabled": "",
"expired": "", "access-window-start": "", "access-window-end": "",
"valid-from": "", "valid-until": "", "timezone": "$timezone",
"guac-full-name": "$fullname", "guac-organization": "$organization",
"guac-organizational-role": "" } } EOF ) done < "$csvfile" |
Now running |./demo.bash| should create the 3 users *peter*, *sepp* and
*jeff*.
Worked for me, maybe works for you, too.
Regards
Peter
​