[英]Creating the issue with assigning the customer as the reporter with Jira API?
I would like to create new customer if it does not exist and create new issue setting this customer as reporter in PHP with Jira API.如果新客户不存在,我想创建新客户,并使用 Jira API 创建新问题,将此客户设置为 PHP 中的记者。
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'.我使用带有POST字段'fullName'和'email'的API'servicedeskapi/customer'创建新客户,然后使用带有参数'fullName'和'email'的参数'reporter'的API'api/2/issue'创建新问题.
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": "kamilszmit2@live.com",
"key": "kamilszmit2@live.com",
"emailAddress": "kamilszmit2@live.com",
"displayName": "kamilszmit2",
"active": true,
"timeZone": "Europe\/Warsaw",
"_links": {
"jiraRest": "https:\/\/jira-address\/rest\/api\/2\/user?username=kamilszmit2%40live.com",
"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?username=kamilszmit2%40live.com"
}
}{
"fields": {
"project": {
"key": "AP"
},
"summary": "test",
"description": "test",
"reporter": {
"fullName": "kamilszmit2",
"email": "kamilszmit2@live.com"
},
"issuetype": {
"id": "10108"
}
}
}{
"id": "11187",
"key": "AP-351",
"self": "https:\/\/jira-address\/rest\/api\/2\/issue\/11187"
}
The customer and the issue are created but the customer is not set as reporter of the issue .创建了客户和问题,但未将客户设置为问题的报告者。 The same problem occurs if customer already exists and when only the parameter 'fullName' or 'email' of the parameter 'reporter' is used.如果客户已经存在并且仅使用参数“reporter”的参数“fullName”或“email”,则会出现同样的问题。
What am I doing wrong?我究竟做错了什么? How to create Jira issue with the customer as the reporter?如何与客户作为记者创建 Jira 问题? Could you help me?你可以帮帮我吗?
via REST, I have managed to set the reporter by using the name
parameter, instead of fullname
.通过 REST,我设法使用name
参数而不是fullname
来设置记者。
"fields": {
"project": {
"key": "AP"
},
"summary": "test",
"description": "test",
"reporter": {
"name": "kamilszmit2"
},
"issuetype": {
"id": "10108"
}
Other things I would check:我会检查的其他事项:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.