【问题标题】:jira rest api error in creating issue创建问题时的jira rest api错误
【发布时间】:2014-09-20 16:43:54
【问题描述】:

您好,当我尝试使用带有 php.Error(s) 的 php.Error(s) 在 jira 中创建问题时,我遇到了以下错误: 对象(stdClass)[1] 公共“错误消息”=> 数组(大小=0) 空的 公共“错误”=> 对象(stdClass)[2] public 'summary' => string 'Field 'summary' 不能被设置。它是 不在适当的屏幕上,或未知。 (长度=79) public 'description' => string 'Field '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 的字段。 我想知道如何纠正这个错误。

【问题讨论】:

    标签: php rest


    【解决方案1】:

    虽然我看到这是近一年前提出的问题,但我会继续回答:

    出现“不在适当的屏幕上,或未知”错误是因为您使用的帐户无权查看这些字段。

    使用您提供给服务的帐户凭据登录到您的 JIRA 实例,并尝试在您用作 $new_issue["fields"]["project"]["key"] 值的同一队列(项目)中创建票证。 这很重要,因为不同的队列将具有不同的权限。当表单出现用于创建问题的字段时,您可能不会看到“摘要”和“描述”字段。您正在使用的帐户需要添加到管理员组(还有其他具有不同权限的组,例如开发人员和成员)。

    【讨论】:

    • 嗯,我看到了这些字段。而且我也是 jira 的管理员-但我收到了同样的错误。您对此有任何其他信息吗?
    • 我们通过将我们正在使用的帐户(用于访问 API)添加到“用户和角色”下的“管理员”角色来解决此问题。对我们来说,在“plugins/servlet/project-config/AC/roles”下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多