Forums

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

How to use REST API to remove startDate from ProjectVersions (aka Releases, FixVersions)

Leon
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!
August 5, 2020

We've sucessfully been using api-group-project-versions/#api-rest-api-2-version-id-put to synchronize version information (name, startDate, releaseDate, description) across multiple projects. 

However, I get a 400 when I try and remove a startDate, either by omitting it, or by setting to "", "0". So my question is, how can I remove a startDate from a fixVersion?

example 1: PUT https://our-jira-server/rest/api/2/version/53756 
--> w/ empty startDate == 400

{
"description": "An excellent version",
"name": "New Version 1",
"startDate" : "",
"releaseDate": "2010-07-06"
}

example 2: PUT https://our-jira-server/rest/api/2/version/53756
--> w/ 0 as startDate == 400

{
"description": "An excellent version",
"name": "New Version 2",
"startDate" : 0,
"releaseDate": "2010-07-06"
}

example 3: PUT https://our-jira-server/rest/api/2/version/53756
--> omitting startDate == startDate left unchanged (obviously) 

{
"description": "An excellent version",
"name": "New Version 3",
"releaseDate": "2010-07-06"
}

 

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
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.
August 5, 2020

Hi @Leon -- Welcome to the Atlassian Community!

I recall seeing another post suggesting setting to the minimum date value, or null, to clear a date/time field with JSON.  Have you tried either of those?


Best regards,

Bill

Leon
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!
August 5, 2020

Bill you wonderful man! That did the trick - thank you!

{
"description": "An excellent version",
"name": "New Version 3",
"releaseDate": "2010-07-06",
"startDate": null
}

Note to others that I'm working in Python, and that json.dump() will convert None to a json null

payload = json.dumps( {
"name": "New Version 3",
"description": "Wow, look at me",
"startDate": None, # <----- will be converted to json null
"releaseDate": "2020-07-22"} )
Like Bill Sheboy likes this
Bill Sheboy
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.
August 5, 2020

Leon, I am glad that worked for you!

Maximilian Floß January 25, 2024

@Bill Sheboy 

I am also using Json syntax for updating fields in my Jira automation Action "Send Web request" in which I create an issue.

I want to update several fields from the triggerIssue. But some fields are empty in the triggerissue and therefore no value can be set and the web request is not successful. 

 

{
"fields":{

"customfield_10853": {"value":"{{issue.customfield_10853}}"},
"customfield_10683": {"value":"{{issue.customfield_10683}}"},
"customfield_10682": {"value":"{{issue.customfield_10682}}"}

}
}

 Current Situation:

When one of the customfields in the triggerissue is empty I get an error because no value can be set in the issue.

What I Want:

But when the customfield of the trigger issue is empty the customfield of the updated issue should be also empty.

I know that I can set a customfield to empty by using the following code:

{
"fields":{

"customfield_10853": null,
"customfield_10683": null,
"customfield_10682": null

}
}

I was wondering If can solve the problem by using a default value which is "null":

Like this: 

 {
"fields":{

"customfield_10853": {"value":"{{issue.customfield_10853|null}}"},
"customfield_10683": {"value":"{{issue.customfield_10683|null}}"},
"customfield_10682": {"value":"{{issue.customfield_10682|null}}"}

}
}

 But it does not work. Do you have any ideas?

Bill Sheboy
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.
January 25, 2024

Hi @Maximilian Floß 

Perhaps try using conditional logic for each field: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

For example,

{{#if(not(exists(issue.customfield_10853)))}}none{{/}}{{issue.customfield_10853}}

This would check if the value does-not-exist, returning "none" for that, and concatenate the field value on the end (to handle the opposite case).

Kind regards,
Bill

Maximilian Floß January 25, 2024

Hi @Bill Sheboy

Do you mean like this?

{
"fields": {
"duedate": "{{if(not(exists(issue.customfield_10015)))}} none {{/}}{{issue.customfield_10015}}"
}
}
Bill Sheboy
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.
January 26, 2024

Almost...should there be spaces around "none"? And does none need the quotation marks around it?

I have not tried that for this type of field so please test it to confirm, possibly adding two specific conditions: one for the value empty and one for the value not empty.

Suggest an answer

Log in or Sign up to answer