POST method in outbound REST message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 12:14 AM
Hi All,
Can we define HTTP query parameters of post method (defined in outbound REST message) using any script?
My doubt is- here in script I am setting the parameters but there is a possibility there might be no value passed for any one of them (suppose field 'memory').
In that case when no value is there for memory, entire field/key named 'memory' should not be there in the content Shared above. The case SHOULD NOT be like "memory":' '. Rather there should be no memory at all.
TIA,
-Ruchi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 01:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2019 02:08 AM
Hi Ruchi,
We can use JSON and few related methods as below.
REST Message POST Method.
and the script should be as below
var sName = 'Bala_0007';
var sAge = '30';
var sSalary = '';
//Build JSON Object
var reqBody = {};
if (sName)
reqBody['name'] = sName;
if (sSalary)
reqBody['salary'] = sSalary;
if (sAge)
reqBody['age'] = sAge;
try {
//JSON to String
var sReqBodyData = JSON.stringify(reqBody);
var r = new sn_ws.RESTMessageV2('Dummy REST API', 'POST');
r.setStringParameterNoEscape('messageBody', sReqBodyData);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.print(JSON.parse(responseBody));
} catch (ex) {
var message = ex.message;
gs.print(message);
}
This code will adds the field name which has value and send the same.
Regards,
Bala T