Forums

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

Update a version with PUT API

Gustavo Barrios September 22, 2023

Hi community! I am trying to update some version fields but it gives me the following error about this code

def result = put("/rest/api/3/version/${releaseID}")
.header('Content-Type', 'application/json')
.body([
fields: [
description: Descripcion,
name: Nombre,
startDate: FechaInicio,
releaseDate: FechaRelease

]
])
.asString()

2023-09-22 12:41:19.243 INFO - PUT /rest/api/3/version/10675 asString Request Duration: 391ms
2023-09-22 12:41:19.244 WARN - PUT request to /rest/api/3/version/10675 returned an error code: status: 400 - Bad Request
body: {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}
2023-09-22 12:41:19.244 INFO - Serializing object into 'interface java.util.Map'

 

2 answers

1 accepted

0 votes
Answer accepted
Florian Bonniec
Community Champion
September 22, 2023

Hi @Gustavo Barrios 

 

I could be an issue with the type of variable you have in description, name, startDate or releaseDate.

 

Regards

Gustavo Barrios September 22, 2023

Hi @Florian Bonniec These are the variables and how I am capturing them:


Map Issue = get("/rest/api/3/issue/${issue.key}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body

String Descripcion = issue.fields.description
String Nombre = Issue?.fields["summary"]
String FechaRelease = Issue?.fields["customfield_10090"]
String FechaInicio = Issue?.fields["customfield_10171"]
String releaseID = issue.fields["versions"]?.find()["id"]

Florian Bonniec
Community Champion
September 25, 2023

Have validate that each variable has the expected value in the expected format using logging ?

 

You could try to log the body and send it using postman for instance to validate the payload is right.

 

Reagrds

Gustavo Barrios September 25, 2023

I was able to solve it by leaving the code like this, removing fields:

def result = put("/rest/api/3/version/${releaseID}")
.header('Content-Type', 'application/json')
.body([
description: Descripcion,
name: Nombre,
startDate: FechaInicio,
releaseDate: FechaRelease

])
.asString()

 

Thank you all for the help.

0 votes
Tansu Akdeniz
Community Champion
September 22, 2023

Hi @Gustavo Barrios 

Well, url and method seems fine.

Update version

Could you please double check request body (parameters) you send? Doc says ID is required.

Gustavo Barrios September 22, 2023

Hi @Tansu Akdeniz I see that the ID is not required in the request body, is required in 

Path parameters

Suggest an answer

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

Atlassian Community Events