You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
You have a lot of users in a CSV file and you don't want to add them manually to Jira.
Copy & paste the script to a file called createusers.php and modify the 5 "define" values to your needs. Note that adding a password with special characters (like '$') will not work without escaping.
<?php
define('JIRA_URL', 'https://mydomain.com');
define('USER', 'user');
define('PASS', 'pass');
define('CSVFILE', 'users.csv');
define('FILELENGTH', 2048);
function create_user($json) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => JIRA_URL . '/rest/api/latest/user',
CURLOPT_USERPWD => USER . ':' . PASS,
CURLOPT_POSTFIELDS => $json,
CURLOPT_HTTPHEADER => array('Content-type: application/json','User-Agent: x'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => 0
));
$result = curl_exec($ch);
if(!$result) {
trigger_error(curl_error($ch));
exit(1);
}
if (!curl_errno($ch)) {
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 201:
break;
default:
echo "Request failed with HTTP-Code: ", $http_code, "\n";
var_dump($result);
exit(1);
}
}
curl_close($ch);
}
$handle = fopen(CSVFILE, "r");
if ($handle) {
while (($data = fgetcsv($handle, FILELENGTH, ";")) !== FALSE) {
$uname = utf8_decode($data[0]);
$upass = utf8_decode($data[1]);
$uemail = utf8_decode($data[2]);
$udname = utf8_decode($data[3]);
$request = '{"name":"'.$uname.'","password":"'.$upass.'","emailAddress":"'.$uemail.'","displayName":"'.$udname.'","applicationKeys":["jira-software"]}';
echo "New user " . $uname ;
create_user($request);
echo " created.\n";
}
fclose($handle);
} else
echo "The file " . CSVFILE . " could not be opened!\n";
?>
php -f /path/to/createusers.php
.\php.exe -f \path\to\createusers.php
(developed and tested with PHP 7.0.33-0ubuntu0.16.04.1 an Jira Server 7.12.3)
Thomas Deiler
Senior Agile Coach
none
none
225 accepted answers
5 comments