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"
}
}
]
}
}
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.