简体   繁体   English

jira rest api在创建问题时出错

[英]jira rest api error in creating issue

hi i am getting following error when trying to create an issue in jira using rest api with php.Error(s) creating issue: object(stdClass)[1] public 'errorMessages' => array (size=0) empty public 'errors' => object(stdClass)[2] public 'summary' => string 'Field 'summary' cannot be set. 嗨,我在尝试使用rest api和php在jira中创建问题时遇到以下错误。创建问题的错误:object(stdClass)[1] public'errorMessages'=> array(size = 0)empty public'errors '=> object(stdClass)[2] public'summary'=>字符串'Field'summary'不能设置。 It is not on the appropriate screen, or unknown.' 它不在适当的屏幕上,或者未知。” (length=79) public 'description' => string 'Field 'description' cannot be set. (length = 79)public'description'=>字符串'field'description'不能设置。 It is not on the appropriate screen, or unknown.' 它不在适当的屏幕上,或者未知。” (length=83) ` i am using the following source code: (length = 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";
 }

 ?>

the fields with xxxx are replaced for security reason. 出于安全原因,带有xxxx的字段已替换。 i want to know how i can correct this error. 我想知道如何纠正此错误。

While I see this was asked nearly a year ago, I'll go ahead and answer: 当我看到这是一年前提出的问题时,我会继续回答:

The "not on the appropriate screen, or unknown" error occurs because the account you're using does not have permission to view those fields. 发生“不在适当的屏幕上,或未知”错误,因为您使用的帐户无权查看这些字段。

Log into your JIRA instance with the account credentials you are providing to the service, and try to create a ticket in the same queue (project) that you are using as the value of $new_issue["fields"]["project"]["key"] . 使用要提供给服务的帐户凭据登录到JIRA实例,并尝试在与$new_issue["fields"]["project"]["key"]的值相同的队列(项目)中创建票证。 $new_issue["fields"]["project"]["key"] This is important, as different queues will have different permissions. 这很重要,因为不同的队列将具有不同的权限。 When the form comes up with the fields for creating an issue, you likely will not see the "summary" and "description" fields. 当表单提供了用于创建问题的字段时,您可能不会看到“摘要”和“描述”字段。 The account you're using will need to be added to the Administrator group (there are other groups with differing permissions, such as Developer and Member). 您正在使用的帐户将需要添加到Administrator组(还有其他具有不同权限的组,例如Developer和Member)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM