简体   繁体   中英

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. It is not on the appropriate screen, or unknown.' (length=79) public 'description' => string 'Field 'description' cannot be set. It is not on the appropriate screen, or unknown.' (length=83) ` i am using the following source code:

<?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. 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"] . 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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