Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How-to create multiple customers in Jira Service Management (Cloud) with one batch run

Your Requirement

You have a lot of customers in a CSV file and you don't want to add them manually to Jira Service Management as customers.

Your skills

  • you know how to create and edit CSV files
  • you can edit configuration files
  • you have Jira Administrator Global permission, app scope ADMIN and OAuth scopes manage:servicedesk-customer
  • you have PHP installed
    • for Linux: there a packages for most distributions available (OpenSUSE: zypper install php php-curl)
    • for Win: get a package here
      • enable curl in php.ini: extension=C:\<path to>\php\ext\php_curl.dll
      • enable ssl in php.ini,: extension=C:\<path to>\php\ext\php_openssl.dll
  • (optional) PHP coding skills

Before you run the script you should know

  • creating new customers is 'silent'. They don't know that a new account exists. The script is sending emails to them, instructing how to reset the password.
  • to deactivate sending of emails, leave SENDER empty.
  • a mail relay must be available for sending mails. Read this.
  • the created customer need to set the password. This cannot be done with the REST API.

Prepare the CSV file

  • one line per new customer
  • the delimiter is ";"
  • column 1 = email
  • column 2 = displayed user name
  • no header row is required
  • save the file as customers.csv

Adapt the script to your needs

Copy & paste the script to a file called create_customers.php and modify the "define" values to your needs. You will require an API-Token.


define('JIRA_URL', '');
define('EMAIL', '');
define('APITOKEN', 'rahHWQ61rElyFHmsz9H6ABv');
define('CSVFILE', 'customers.csv');
define('FILELENGTH', 2048);
define('SENDER', '');
define('PORTAL', '/servicedesk/customer/portal/1');
define('SUBJECT', 'New account for Jira Service Management Portal');
define('BODY', 'we have just registered you at our JSM portal. Please follow the link below, login with your email and press the link "Forgot your password?" to get a reset email mail sent from the cloud.' . PHP_EOL . PHP_EOL);

function create_customer($json) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt_array($ch, array(
CURLOPT_URL => JIRA_URL . '/rest/servicedeskapi/customer',
CURLOPT_HTTPHEADER => array('Content-type: application/json','User-Agent: x'),

$result = curl_exec($ch);

if(!$result) {

if (!curl_errno($ch)) {
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 201:
echo "Request failed with HTTP-Code: ", $http_code, "\n";


$header = 'From: '. SENDER . "\r\n" . 'X-Mailer: PHP';

$handle = fopen(CSVFILE, "r");
if ($handle) {
while (($data = fgetcsv($handle, FILELENGTH, ";")) !== FALSE) {

$uemail = utf8_decode($data[0]);
$udname = utf8_decode($data[1]);

$request = '{"displayName": "' . $udname . '", "email": "'. $uemail . '"}';

echo "New customer " . $uemail ;
echo " created.";

if (strlen(SENDER) > 1) {
mail($uemail, SUBJECT, 'Dear ' . $udname . ',' . PHP_EOL . PHP_EOL . BODY . JIRA_URL . PORTAL, $header);
echo " info-mail sent.";
echo PHP_EOL;
} else
echo "The file " . CSVFILE . " could not be opened!\n";


What the script does:

  1. open the csv file, read line by line
  2. per line, one REST request is sent to create the customer
  3. (optional) per line, an email is sent to the customer

Run the script on Linux

php -f /path/to/create_customers.php

Run the script on Win PowerShell

.\php.exe -f \path\to\create_customers.php

(tested with PHP 8.0.5 on OpenSUSE Tumbleweed)

Follow this link for How-to create multiple users in Jira with one batch run (Server).

1 comment

Mohammed Amine Community Leader Jun 09, 2021

Interesting, nice !


Log in or Sign up to comment
Community showcase
Published in Jira Service Management

JSM Jira Automation: How to Send SLA Breached Notifications

Hi Everyone, In   this tutorial,  we will show you how you can monitor an SLA, and send notifications before or after the SLA has been breached.   SLA Threshold Trigger The SLA t...

731 views 5 13
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you