Hi
Try this:
Add this import:
import groovy.json.JsonBuilderAnd this line before the comment that reads "API POST"
def finalJSON = new JsonBuilder(jsonBody).toString()).build()That should output the JSON in the proper format.
Do say if I can help you further.
Cheers!
DYelamos
Thank you for the assist. Managed to get it working. Appreciate the help.
I ended up getting the concatenation working as base and it posts successfully. But will look at your code as well for a more robust method I think.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks:
Could you mark this answer as accepted so that other users know that this thread has been answered?
Do say if I can help you further.
Cheers
DYelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to update a request using the your code
def body = [:]
body.put("IssueNumber","XCAP-688")
body.put("Priority","P4 (No Impact/Notify)")
def baseUrl = new URL("http://xxx/xxx/UpdatePriority");
HttpURLConnection connection = baseUrl.openConnection() as HttpURLConnection;
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body) }
connection.connect();
log.info ("URL=" +baseUrl +" Status= "+connection.getResponseCode() as String)
But it is throwing 500 error(whereas there is no issue with the api.Not sure why is it giving 500 error). If i am trying to pass json data as below I am getting 400 error
def body = """{"Priority": "P4 (No Impact/Notify)", "IssueNumber": "XCAP-688"}"""
Can you help me in passing json data
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.