I want to use data i have parsed form precious service and make post request for writing this data in another databasei in postman my post request looks like this
and this request gives me this exception : Required request body is missing
How can i make post request so that my service could recognize request body?
I mean, you configured the body from TypeText and the value as JSON in the request of your screenshot above. The problem could be, that the JSON is not valid because the process variables e.g. cardNumber are not correct set.
You can try to use the connector configuration from your screenshot and instead of using the process variable values you could use hard coded values.
Of course, you can also use a script to build the body.
ok , thank you @kristin for you replies, but by the way i have several question about script implementation, i have generated script which should give me json request body but even this response isn’t accaptable for my post request body here is my jss code example, what should i cahnge to make my requst body accaptable for post request body?
var dat1=S(execution.getVariable("restResponse"));
var id = dat1.prop("id").value();
var name = dat1.prop("Name").value();
var data = new Object();
data.id = id;
data.Name = name;
execution.setVariable("request body",data);
2018-02-01 03:37:23.799 WARN 9504 — [io-9001-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void ge.sda.springTest.Controller.DocumentController.addTopic(ge.sda.springTest.Data.DocumetsEntity)
yes i use http connector
in url i have this link http://localhost:9001/documents whih should make post request based on json data i will give it
3.i have body parameter afeter headers parameter in which i have this script:
var dat1=S(execution.getVariable(“restResponse”));
var id = dat1.prop(“id”).value();
var name = dat1.prop(“name”).value();
var data = new Object();
data.id = id;
data.name = name;
execution.setVariable(“request body”,data);
it should make json request body and send it to post request
Do you want to execute a POST request to http://localhost:9001/documents?
Do you want to use as body with the created data object from the script? Or do you want to use the restResponse process variable as body? It looks that both contain the same content…
When you want to use the restResponse process variable as body, it should be enough to write in your script: S(execution.getVariable('restResponse'));
Then you need to configure an output parameter in the http connector configuration. This output parameter contains the response of your post request.
@kristin in my case restResponse’ is response from previous get request( i mean i make one service invokation to read data from it and then i want to get this data to my post request) when i try this
var data=S(execution.getVariable(“restResponse”));
execution.setVariable(“Request Body”,data);
i guess this doesn’t work inside my output parameter?
i want to use restResponse as a body for my post request
@kristin you are right, according to your bnpm script example i shoudd write inside my input parameter ‘body’ something like this:
var dat1=S(execution.getVariable(“restResponse”));
execution.setVariable(“PostResponse”,dat1);
and then write in output parameter PostResponse and it will help me trasnform previous response data into post request body?