简体   繁体   中英

How to set Affects Version field via JIRA REST API - PHP

I would like to update the affects versions field via JIRA REST API. But I'm getting an error:

{"errorMessages":[],"errors":{"versions":"Affects Version/s is required."}}

I have the following code:

public function requestBug($summary, $components, $affectsVersions, $fixVersions, $assignee, $environment, $description)
{
    $json = Array ( "fields" => Array (
                                        "project" => Array( "id" => 10051),
                                        "summary" => $summary,
                                        "issuetype" => Array ( "name" => "Bug" ),
                                        "components" =>Array(0 => Array("id" => $components)),
                                        "versions" =>Array(0 =>Array("affectsVersion" => $affectsVersions)),
                                        "versions" =>Array(0 =>Array("fixVersion" =>$fixVersions)),
                                        "assignee" => Array("name" => "$assignee"), 
                                        "environment" => "$environment", 
                                        "description" =>$description
                                      )
                 );

    return $json;
}

Please assist. I came across this link, but doesnt work for me

I had the same problem and the given answer (even with links provided) did not help me much. I played around with all sorts of variations and finally this piece of JSON worked to change the affected version of an item to "Version 2.0.0":

"versions":
       [
         { "Affects Version/s" : "Version 2.0.0" 
         },
         { "name": "Version 2.0.0" 
         }
       ]

Meta data looks like this:

"versions":{"required":true,"schema":
{"type":"array","items":"version","system":"versions"},"name":"Affects Version/s",....

Especially irritating and inconsistent is the fact that the very same field is exported by JIRA as <version>Version 2.0.0</version> in XML and for queries affectedVersion is to be used.

There are a few example of "edit issue" requests here .

You want to send a json that includes something like this:

{
    "fields":
    {
        "versions":["1.0.0","1.1.0"],
        "fixVersions":["2.0.0"]
    }
}

In your code you use the key "versions" both for "Fix version(s)" and "Affected version(s)", which won't work. Also, you don't have to use additional "affectsVersion" or "fixVersion" keys.

You can also get more info about which fields you can edit and which values they allow using this REST call: GET /rest/api/2/issue/{issueIdOrKey}/editmeta

Try it out for an issue you want to edit and it should put you on the right track. The output will also show that the "versions" key corresponds to the "Affected version(s)" field.

from jira import JIRA

auth_jira = JIRA('jira.your-oraganizsation.com', auth=('username', 'password'))

new_issue = auth_jira.create_issue(project='project_name', summary='jira_summary', description='jira_description', issuetype={'name': 'Defect'}, fields={'versions': [{'name': '1.0.0'}, {'name': '18.8.0'}] })

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