hi我在试图使用rest api和php在jira中创建问题时遇到以下错误。创建问题时出错:对象(stdClass)[1]public"errorMessages"=>数组(大小=0)空的公共"错误"=>对象(stdClass)[2]public"summary"=>无法设置string"字段"summary"。是的不在合适的屏幕上,或者未知(长度=79)public"description"=>string"字段"description"不能为设置它不在合适的屏幕上,或者未知(长度=83)`我正在使用以下源代码:
<?php
define('JIRA_URL', 'xxxxxxxx');
define('USERNAME', 'xxxxxxxxx');
define('PASSWORD', 'xxxxxxxx');
function post_to($resource, $data) {
$curlname=CURLOPT_POST;
$curlvalue=1;
$jdata = json_encode($data);
$ch = curl_init();
curl_setopt_array($ch, array(
$curlname => $curlvalue,
CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . $resource,
CURLOPT_USERPWD => USERNAME . ':' . PASSWORD,
CURLOPT_POSTFIELDS => $jdata,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
function create_issue($issue) {
return post_to('issue', $issue);
}
$new_issue = array(
'fields' => array(
'project' => array('key' => 'xxx'),
'summary' => 'Test via REST',
'description' => 'Description of issue goes here.',
'issuetype' => array('name' => 'Task')
)
);
$result = create_issue($new_issue);
if (property_exists($result, 'errors')) {
echo "Error(s) creating issue:'n";
var_dump($result);
} else {
echo "New issue created at " . JIRA_URL ."/browse/{$result->key}'n";
}
?>
出于安全原因,带有xxxx的字段被替换。我想知道如何纠正这个错误。
虽然我看到这是近一年前提出的问题,但我会继续回答:
出现"不在适当的屏幕上,或未知"错误是因为您使用的帐户没有查看这些字段的权限。
使用向服务提供的帐户凭据登录到JIRA实例,并尝试在用作$new_issue["fields"]["project"]["key"]
值的同一队列(项目)中创建票证这很重要,因为不同的队列将具有不同的权限当表单中出现用于创建问题的字段时,您可能看不到"摘要"answers"说明"字段。您正在使用的帐户需要添加到管理员组(还有其他具有不同权限的组,如开发人员和成员)。