Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble setting the fix version rest api via powershell

Brijesh Gurung
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2020

I am a novice in rest api with JIRA so please excuse me for my question.

I am trying to set the fix version while transitioning the issue in JIRA via restapi via powershell.

Fixversion is a list of defined values and I am trying to set one of them. I continue to get data was not an array or expected object error.

This is how the fixversion list look like in html page...

<option value=\"14233\">\n                   

             2.4474.00012\n               

</option>\n      ....                                         

 

My code:

$transitionField= @()
$transitionField += @{'fixVersions' = @{value = '2.4508.00014'}}

Invoke-JiraIssueTransition -Issue CSAPPS-2849 -Transition 291 -Fields $transitionField -Credential $cred

Json payload that is being sent

{
"transition": {
                        "id": 291
                    },
"update": {
                   "fixVersions": [
                                           { 
                                              "set": {
                                                            "value": "2.4508.00014"
                                                        }
                                            }
                                           ]
                 }
}

 

2 answers

2 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 27, 2020

Hi Brijesh,

I see that you're using powershell to try to set or update a fixversion in Jira using the REST API.  You are correct that this field is expecting the data to be in an array format.  However for the REST API methods to change values in this field, those commands to 'add', 'remove', and/or 'set' are also in an array format within that field.

Which means that when you run this command, you could be just adding a new fixVersion version, removing one or more, OR you could be ignoring all values that might have been previously in that field for that issue and instead just setting a new value.

However you can't use 'value' to set fixversion.  Instead you either need to know the "id" of that version and assign that way, OR use the "name".   I have tested this out using curl (forgive me that it's not exactly the same as powershell, but for the json data payload part it should be exactly the same here).

 

You could just add a fixVersion without changing other fixversion values currently assigned to issue:

curl --request PUT \
--url 'https://[example].atlassian.net/rest/api/3/issue/SCRUM-35' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json' \
--data '{"update": {"fixVersions":[{"add": {"id": "10002"}}]}}'


Or you can set there to be only one fix version with a command such as:

curl --request PUT \
--url 'https://[example].atlassian.net/rest/api/3/issue/SCRUM-35' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json' \
--data '{"update": {"fixVersions":[{"set": [{"id": "10002"}]}]}}'

 

You can also set it by the version name, (which again removes all other previous values in that field on this issue here and just uses this one value).

curl --request PUT \
--url 'https://[example].atlassian.net/rest/api/3/issue/SCRUM-35' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json' \
--data '{"update": {"fixVersions":[{"set": [{"name": "Version 2.0"}]}]}}'

 

Try that, it should help make this work.

Let me know if you run into any problems with this.

Andy

0 votes
Italo Qualisoni [e-Core]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2020

Hi @Brijesh Gurung ,

Can you try to make your set an array of objects? 

...

"set": {[

  {

     "name":"2.4508.00014"

  }

]}

...

Also change value to name since  2.4508.00014 is the fixversion name.

I've added the formatted version here: https://textbin.net/C55bFp8saT 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events