Hi ,
I'm trying to post some data from JIRA to external system by calling rest API using script Runner.
API expect the List of object. API signature is;
@PostMapping(value="add")
public ResponseEntity<ResponseDTO> postWeightDetails(@RequestBody List<WeightDetail> WeightDetailList)
WeightDetail contains following:
ItemId, Item weight and WeightUnit
So Expected request Body is:
[
{
"ItemiD": "ABC-ITEM",
"weight": 10,
"weightUnit": "KG"
}
]Now from JIRA i'm calling this way from RestEnd Point:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import javax.ws.rs.core.Response
import javax.ws.rs.core.MultivaluedMap
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
@BaseScript CustomEndpointDelegate delegate
SaveEaseWeightDetails(httpMethod: "POST"){ MultivaluedMap queryParams, String body ->
HTTPBuilder http = new HTTPBuilder("http://localhost:8082/logicalApp/ease/weight/add")
def saveResponse = http.request(Method.POST, ContentType.JSON){
requestContentType = ContentType.JSON
body = [{
"ItemId": "ABC-123",
"weight": 10,
"weightUnit": "KG"}
]
response.success = { resp ->
log.info "Success ! ${resp.status}"
}
response.failure = { resp, reader ->;
log.error "Failed : [URI : ${uriPath}, Status: ${resp.status}]"
}
}
return Response.ok(new JsonBuilder(saveResponse).toString())
.header("Access-Control-Allow-Origin", "*").build();
}
Script is not working and not finding the issue.