Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create JIRA issue on a tabbed screen via REST API - PHP

Tags:

rest

php

jira

I have the following JIRA screen with TABS, and I would like to create an vISSUE on the "Resquestor Details tab via REST API.enter image description here"

Now I have the following code and I'm not sure where to specify the tab name.

 public function createTestData($firstName, $surname, $userID, $email, $testPortfolio, $projectName,$projectID,
                            $newSystem, $newProduct, $requirementsFunction, $evinronment, $dueDate, $region,
                            $summary, $description)
{


    if ($this->finduser($email) < 1)
        {
            $json = Array ( "fields" => Array (
                                                "project" => Array
                                                    ( "id" => 20207 ),
                                                        "summary" => "$summary",
                                                        "description"=>"$description",
                                                        "issuetype" => Array ( "name" => "Test Data" ),
                                                        "customfield_14421" => "$firstName",
                                                        "customfield_15026" =>"$lastName",
                                                        "customfield_14490" =>"$userID",
                                                        "customfield_14415" =>"$email",
                                                        "customfield_156681" =>Array ("value" => "$testPortfolio"),
                                                        "customfield_12103" =>"$projectName",
                                                        "customfield_14236" =>"$projectID",
                                                        "customfield_14430" =>"$newSystem",
                                                        "customfield_15672" =>"$newProduct",
                                                        "customfield_15673" =>Array ("value" => "$requirementsFunction"),   
                                                        "customfield_15685" =>Array ( "value" => "$environment"),
                                                        "customfield_15700" =>"$region",                                           
                                                        "reporter" =>Array ("name" => "API"  )
                                                )
                        );
        }


    return $json;
}

I had a look at the Documentation but I don't really get it or see it anywhere.

I get this error:

cannot be set. It is not on the appropriate screen, or unknown. for all fields But the fields are on the correct issue Type and permissions are also correct.

like image 568
kya Avatar asked Jul 14 '16 12:07

kya


People also ask

How do I create an issue in Jira programmatically?

To create an issue, you will need to know certain key metadata, like the ID of the project that the issue will be created in, or the ID of the issue type. You can request the create metadata for all issue types across all projects by using the createmeta resource.

Does Jira support REST API?

The Jira Software and Jira Service Management applications have REST APIs for their application-specific features, like sprints (Jira Software) or customer requests (Jira Service Management). If you haven't used the Jira REST APIs before, make sure you read the Atlassian REST API policy.


1 Answers

If you use the JIRA Rest API to create an issue, ie. POST /rest/api/2/issue, then you do not need to think about the tabs that are displayed when you view the issue within JIRA. You just have to set all the desired fields and custom fields in the json that you post to JIRA.

You did not list the exact content that you send to JIRA, so I'm not entirely sure which REST resource you use.

The error that you mentioned, indicates that you're trying to set a field that is not available on the "Create Screen" for your project. You can verify this with the GET /rest/api/2/issue/createmeta resource. Probably its output does not list all the fields that you try to set.

To correct this, you have to verify the screen scheme that your project uses and make sure that the "Create Screen" associated with the scheme lists the necessary fields. The relevant JIRA documentation is available here.

As a sidenote: the tabs that you see when you view an issue, are defined in the "View Issue" screen of the project's screen scheme.

like image 65
GlennV Avatar answered Oct 07 '22 03:10

GlennV