Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using REST to set fixVersions

I try to use REST API v2 to set a single specific fixVersion to an issue.

I used the example from here: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put

 

>>> url = 'https://company.atlassian.net/rest/api/2/issue/ISSUE-123'
>>> auth = ('user@company.com', 'Token')
>>>
>>> headers = {
... "Accept": "application/json",
... "Content-Type": "application/json"
... }
>>>

Initial state:
>>> fix_versions = requests.get(url, auth=auth, headers=headers).json()['fields']['fixVersions']
>>> print([fv['name'] for fv in fix_versions])
['Future', '3.1_hotfix', '3.2']
>>>

Use set to update fixVersions; nothing happens:
>>> payload = json.dumps({'update': {'fixVersions': [{'set': [{'name': 'Future'}]}]}})
>>> requests.put(url, auth=auth, headers=headers, data=payload)
<Response [204]>
>>>
>>> fix_versions = requests.get(url, auth=auth, headers=headers).json()['fields']['fixVersions']
>>> print([fv['name'] for fv in fix_versions])
['Future', '3.1_hotfix', '3.2']
>>>

Remove another fixVersion; nothing happens:
>>> payload = json.dumps({'update': {'fixVersions': [{'remove': {'name': '3.1_hotfix'}}]}})
>>> requests.put(url, auth=auth, headers=headers, data=payload)
<Response [204]>
>>>
>>> fix_versions = requests.get(url, auth=auth, headers=headers).json()['fields']['fixVersions']
>>> print([fv['name'] for fv in fix_versions])
['Future', '3.1_hotfix', '3.2']
>>>

Set the fixVersion using 'fields' instead of 'update'; fixVersion is removed instead of set:
>>> payload = json.dumps({'fields': {'fixVersions': [{'set': [{'name': 'Future'}]}]}})
>>> requests.put(url, auth=auth, headers=headers, data=payload)
<Response [204]>
>>>
>>> fix_versions = requests.get(url, auth=auth, headers=headers).json()['fields']['fixVersions']
>>> print([fv['name'] for fv in fix_versions])
['3.1_hotfix', '3.2']

 

What am I doing wrong?

1 answer

1 accepted

0 votes
Answer accepted
Andy Heinzer Atlassian Team Mar 22, 2021

Hi @mrytikov 

I see that you are trying to use the REST API in Jira Cloud in order to add/remove/set fixVersions on an issue.  I took a closer look at your payloads here, and I think I found the problem.  First thing is that, in general, we use the 'fields' when creating the issue, the 'update' directive when updating the issue. The use of 'set' is expected to overwrite any other existing values in an array field like versions, labels, components, etc.  Also in your original post, it was not clear to me if you were using the POST directive (to create the issue) or the PUT directive, to update the issue.  Once the issue is created, you can just use the PUT directive to update that issue.

The next thing might be more environmental, but using the single quote versus double quotes can sometimes cause problems like this.  The json payload might accept it, but I have found it to sometimes be a source of problems.  It looks like you might be using python to do make these calls, and while I'm not an expert in python, I was able to recreate this same kind of response using curl.  I ran into the same problems when using your payloads.  I think you had an extra square bracket in your payload.  Here are my examples:

Add a specific version:

curl --request PUT \
--url 'https://[redacted].atlassian.net/rest/api/2/issue/SCRUM-11' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '
{
"update": {
"fixVersions": [
{"add":
{"name": "Version 3.0"}
}
]
}
}'


Remove a specific version:

curl --request PUT \
--url 'https://[redacted].atlassian.net/rest/api/2/issue/SCRUM-11' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '
{
"update": {
"fixVersions": [
{"remove":
{"name": "Version 3.0"}
}
]
}
}'

Or you can make one call to do both at the same time:

curl --request PUT \
--url 'https://[redacted].atlassian.net/rest/api/2/issue/SCRUM-11' \
--header 'Authorization: Basic [redacted]' \
--header 'Content-Type: application/json; charset=utf-8' \
--data '
{
"update": {
"fixVersions": [
{"remove":
{"name": "Version 3.0"}
},
{"add":
{"name": "Version 2.0"}
}
]
}
}'

 

The link you cited of https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put is correct, but it doesn't exactly show you the syntax of fixVersion field precisely.  But that example does show a single REST call that adds and then removes a label, like so:

"labels": [
      {
        "add": "triaged"
      },
      {
        "remove": "blocker"
      }
    ]

I hope this helps.

Andy

Hi, Andy.

Thanks for the reply.

Unfortunately, it didn't work: PUT request with data

{    
"update": {
  "fixVersions": [
    {
      "remove": {
        "name""3.1_hotfix"
      }
    }
  ]
}}

returned 204, but the fixVersion was not deleted.

 

I just found, that versions, that I'm unable to remove have parameters "archived" and "released" set to true, can it be the root of a problem? Maybe I just can't remove archived fixVersion or something like that?

Andy Heinzer Atlassian Team Mar 23, 2021

Ah, yes that is another possible cause of the problem here.  When a version has been archived in a project, you are no longer able to add that version or remove it from any issues.  It is intended to act as a historical snapshot of that version according to our documentation in Manage versions

You can see the same behavior within the web UI of Jira when an issue has a version that is archived:

Screen Shot 2021-03-23 at 2.21.38 PM.png

It is not removable from there either.

A project administrator could un-archive that version.  If they were to do that, then you could add/remove that specific version to issues again.

So, that's the cause of the problem then. Thanks for your help!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

107 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you