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

Creating the issue with assigning the customer as the reporter with Jira API Edited

I would like to create new customer if it does not exist and create new issue setting this reporter as customer in PHP with JIra API. I am trying do this in this way:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');

$postvars = array('fields' => array('project' => array('key' => 'AP'), 'summary' => $body, 'description' => $body, 'reporter' => null));

$postvars['fields']['issuetype'] = array("id" => '10108');
$postvars['fields']['reporter']['fullName'] = $name; //POST field of customer's name to set customer as the reporter of new issue
$postvars['fields']['reporter']['email'] = $email; //POST field of customer's email address to set customer as the reporter of new issue

curl_setopt($ch, CURLOPT_URL, 'https://jira-address/rest/servicedeskapi/customer');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-ExperimentalApi: opt-in'));
curl_setopt($ch, CURLOPT_POSTFIELDS,
json_encode(array('fullName' => $reporterName, 'email' => $email))); //POST fields for creating new customer
$r = curl_exec($ch); //sending request for creating new customer
echo json_encode(json_decode($r), JSON_PRETTY_PRINT); //printing response of request for creating new customer

curl_setopt($ch, CURLOPT_URL, 'https://jira-address/rest/api/2/issue/');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postvars));
$r = curl_exec($ch); //sending request for creating new issue
echo json_encode($postvars, JSON_PRETTY_PRINT); //printing POST fields of the request of creating new issue
echo json_encode(json_decode($r), JSON_PRETTY_PRINT); //printing the response of the request for creating new issue

If the customer does not exist, the response is:

    "name": "",
    "key": "",
    "emailAddress": "",
    "displayName": "kamilszmit2",
    "active": true,
    "timeZone": "Europe\/Warsaw",
    "_links": {
        "jiraRest": "https:\/\/jira-address\/rest\/api\/2\/user?",
        "avatarUrls": {
            "48x48": "https:\/\/jira-address\/secure\/useravatar?avatarId=10122",
            "24x24": "https:\/\/jira-address\/secure\/useravatar?size=small&avatarId=10122",
            "16x16": "https:\/\/jira-address\/secure\/useravatar?size=xsmall&avatarId=10122",
            "32x32": "https:\/\/jira-address\/secure\/useravatar?size=medium&avatarId=10122"
        "self": "https:\/\/jira-address\/rest\/api\/2\/user?"
    "fields": {
        "project": {
            "key": "AP"
        "summary": "test",
        "description": "test",
        "reporter": {
            "fullName": "kamilszmit2",
            "email": ""
        "issuetype": {
            "id": "10108"
    "id": "11187",
    "key": "AP-351",
    "self": "https:\/\/jira-address\/rest\/api\/2\/issue\/11187"

I create new customer using API ‘servicedeskapi/customer’ with POST fields ‘fullName’ and ‘email’ and then I create new issue using API ‘api/2/issue’ with parameters ‘fullName’ and ‘email’ of parameter ‘reporter’. New customer and new issue are created but new customer is not set as the reporter of this issue in Jira. The same problem occurs if customer already exists and when only the parameter ‘fullName’ or ‘email’ of the parameter ‘reporter’ is used.

What am I doing wrong? How to create Jira issue with the customer as the reporter? Could you help me?

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

2,188 views 15 22
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