[英]Create issue using Jira php API
我正在嘗試使用 jira rest api 創建問題,這是我的代碼:
$new_issue = array(
'fields' => array(
'project' => array('key' => "KEY"),
'summary' => $this->Summary,
'description' => $this->Description,
'issuetype' => array('name' => 'Bug')
)
);
$body = json_encode($new_issue);
self::$handle = curl_init();
curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt(self::$handle, CURLOPT_POSTFIELDS, $body);
curl_setopt_array(self::$handle, array(
CURLOPT_URL => "jiraUrl//rest/api/2/issue/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HTTPHEADER => array("content-type:application/json"),
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => ''
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $username . ':' . $password
));
$response = curl_exec(self::$handle);
$error = curl_error(self::$handle);
我收到此錯誤:{"errorMessages":["由於輸入結束,沒有要映射到對象的內容"]} 有什么建議嗎?
此處缺少結束語:
CURLOPT_URL => "jiraUrl//rest/api/2/issue/
而jiraUrl
可能需要像$jiraUrl
。
所以,我的看法:
CURLOPT_URL => "$jiraUrl//rest/api/2/issue/",
對於仍然想知道如何使用 JIRA REST API 創建問題的任何人,以下最小代碼對我有用:
$url = "http://your.domain.here/rest/api/latest/issue/"
$username = "username";
$password = "password";
$txt = '{
"fields": {
"project": {
"key": "KEY"
},
"summary": "SUMMARY",
"description": "DESCRIPTION",
"issuetype": {
"name": "ISSUETYPE"
}
}
}';
// Create a new cURL resource
$ch = curl_init ();
// Set URL and other appropriate options
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $txt );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_USERPWD, $username . ":" . $password );
$headers = array ();
$headers [] = "Content-Type: application/json";
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
// Grab URL and pass it to the browser
$result = curl_exec ( $ch );
echo $result;
2021 年更新,您可以使用此 PHP Jira REST 客戶端: https : //github.com/lesstif/php-jira-rest-client
<?php
require 'vendor/autoload.php';
use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
use JiraRestApi\JiraException;
try {
$issueField = new IssueField();
$issueField->setProjectKey("TEST")
->setSummary("something's wrong")
->setAssigneeName("lesstif")
->setPriorityName("Critical")
->setIssueType("Bug")
->setDescription("Full description for issue")
->addVersion(["1.0.1", "1.0.3"])
->addComponents(['Component-1', 'Component-2'])
// set issue security if you need.
->setSecurityId(10001 /* security scheme id */)
->setDueDate('2019-06-19')
;
$issueService = new IssueService();
$ret = $issueService->create($issueField);
//If success, Returns a link to the created issue.
var_dump($ret);
} catch (JiraRestApi\JiraException $e) {
print("Error Occured! " . $e->getMessage());
}
並鏈接到Jira 文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.