1
votes

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

  1. Using single quotes around string and double quotes for the XML attributes
  2. Using double quotes and escaping quotes inside with backslashses attributes
  3. Using &quot for quotation marks
  4. Using NetSuite APIs nlapiStringToXML and nlapiEscapeXML
  5. Using DOMParser. I believe there is no DOM in this case
  6. 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\"?>...."
1
Are you looking at console output? It's just showing you how you'd have to code the string if it were to be used as a JavaScript string constant.Pointy
You are saying in Postman? Its like that when I look in the "Raw" body too, is that still normal behavior?nzaleski
I don't know; what I mean to say is, how exactly are you examining the values? JavaScript itself definitely does not do anything like that.Pointy
I am just looking in the body of Postman. It just showing what is being returned.nzaleski

1 Answers

0
votes

RESTlets only support JSON and plain text content types for input and output content.