I have a NetSuite "RESTlet" which is like a REST endpoint. It accepts some JSON from an eCommerce site. It parses out the JSON, then generates some XML which it uses to call a third party shipping API.
I am trying to test out in postman and when I call the RESTlet no matter what it returns the XML wrapped in double quotes and it is escaping the quotation marks with backslashes.
I believe this is my problem with the RESTlet, because I can take the same XML, remove the backslashes from the string, then use it to call the shipping API and it works as hoped.
Things I have tried to not return my XML with escaped quotes
- Using single quotes around string and double quotes for the XML attributes
- Using double quotes and escaping quotes inside with backslashses attributes
- Using " for quotation marks
- Using NetSuite APIs nlapiStringToXML and nlapiEscapeXML
- Using DOMParser. I believe there is no DOM in this case
- I even tried string.replace the "\ for " just to see if that works
My theory is that because the RESTlet is accepting application/json it returning JSON object literal https://stackoverflow.com/a/3154507/3548821 and then this making the string be formatted by escaping the quotation marks.
Probably a little hard to debug but any thought/suggestions would be appreciated.
// build out XML
// code shortened for readability
var xmlRequest = '<?xml version="1.0" encoding="UTF-8"?>'
xmlRequest += '<ns2:RatingRequest xmlns:ns2="http://schemas.....com,">'
xmlRequest += '<RequestToken>4354534</RequestToken>'
return xmlRequest;
returns
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>...."