Error 400 while POST request with JSON

siddharthakadiy
Kilo Contributor

Hi all,

I am trying to send a JSON data through RESTMessage POST using the below steps:

1) I have set ${content} in the content body.

2) I have set http header 'Content-Type' as 'application/json'

3) I have added 'content' in the variable substitutions

In my script include I am using exactly the same code as shown in 'preview script usage' of that post request. Below is the code.

try {

var r = new sn_ws.RESTMessageV2('<Rest module name>', 'post');

r.setStringParameter('content', '{"assetBook":"abc","assetId":"222","assetNumber":"333","assetType":"xyz","description":"test","massAdditionId":"131"}');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

}

catch(ex) {

var message = ex.getMessage();

}

But I am getting a 400 http status response when i run it. I tried using the 'test' link in the post method page with the same data as test value and it works perfectly with 200 status. I am not able to figure out what the issue is as iam using exactly the same code given for preview script.

Please help.

Siddhartha

6 REPLIES 6

Hi Rajendra ,



I am getting HTTP status as 400 even when I click on Test Related link for my POST REST Message , please suggest .


I tried and troubleshooted all . I checked the HTTP headers , tried to delete some of the variable substitutions. Nothing is working . Also we are using MID server.


Please let me know if you require any further information.


Hi Rajendra,



Please see REST Message response code: 400   and help on this. This is the thread I opened for my issue.