How to define optional paramters on POST method content?

krishanu21
Tera Contributor

Hello Community,

 

I've a requirement to avoid sending empty parameters without forming the request body on any script. Is there a way we can handle this on the content of the POST method of a REST message? 

Scenario: There are certain variables on the catalog form which are not mandatory. So if the user does not provide any input to those variables, it should not send any query parameters for those empty values. I've to handle it on the content of the POST method.

krishanu21_0-1718264376041.png

 

1 REPLY 1

Maik Skoddow
Tera Patron
Tera Patron

It's not possible via that approach. Instead you have to build the request body via script and then set the result to the REST Message object manually.

Approach (not the final solution!)

 

var _objRestMessage = new sn_ws.RESTMessageV2("<NAME OF REST Message record");
var _objRequestBody = {};
var _strRequestedBy = '';

if (_strRequestedBy != '') {
	_objRequestBody.requested_by = _strRequestedBy;
}

_objRestMessage.setRequestBody(JSON.stringify(_objRequestBody, null, 4));