How to map a boolean type field in scripted REST API?

Devi12
Giga Guru

Hi,

For Vendor data import I am doing integration using Scripted REST API. The requirement here is: The field "primary contact" is a boolean type (True/False check box), which is not maintained in third party. Third party is able to send Y/N only. For this How can I change my script to map "Y" with "True" and "N" with "False" in Scripted REST API. Is it possible to do the mapping or third party needs to do changes?

Thanks in advance!

6 REPLIES 6

Anil Lande
Kilo Patron

Hi,

If you have created custom Scripted REST API then you can handle this through script.

If you are using OOB API's then you need to contact third part team and ask them to update the request body while making API call and do the mapping at their end.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Kristy Merriam
Administrator
Administrator

Your Scripted REST API could look something like this:

    var str = request.body.dataString;
    var obj = JSON.parse(str);
	
	var primaryBool = false;
	var primaryTF = obj.primaryContact; //Or whatever the name of your request parameter would be
	
	if (primaryTF == 'True')
		primaryBool = true;

I tried this code, it is showing below error.

{
    "error": {
        "message": "Empty JSON string",
        "detail": "SyntaxError: Empty JSON string (sys_script_include.d2426c9ec0a8016501958bf2ac79c775.script; line 155)"
    },
    "status": "failure"
}

This is the declaration:

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    var reqdata = request.body.data;
    var parsedData = reqdata;
    var str = request.body.dataString;
    var obj = JSON.parse(str);
    var primaryBool = false;
    var primaryTF = obj.primary_contact;