Sample Escaped HTML Body for Message Responders API Payload

Hello,
I am trying to create a message responder via API whose response is an HTML body. I tried to escape the HTML body by making the following changes (see code snippet below). However, the API is still failing mentioning that payload is invalid. Can you please let me know what changes need to be made to a raw HTML source text in order to use it as a payload in the messageResponders API. If possible, please provide a sample raw and escaped HTML text. Thank you!!
.replace("\"", """) // Double quote .replace("<", "<") // Less than .replace(">", ">") // Greater than .replace("&", "&"); // Ampersand
Best Answer
-
Hi,
What I often do in these cases is to test the actions in reverse. I would create a responder with html as the response payload and then I would call the GET operation on the REST API to see what the payload looks like.
When I did that with a simple html payload this is what was in the GET response
"text": "<html>\n\t<div>\n\t\t<p>This is \"html\" for a response</p>\n\t</div>\n</html>",
Since the payload is JSON it really only is the double quotes that need to be escaped.
Hope this helps!
1
Answers
-
Hi williammccusker, thank you for the quick reply & the tip regarding "testing in reverse". Following that, I was able to find the correct payload. In addition to the change in double quotation marks, I also had to change:
new line (\n) to "\r\n"
back slash (\) to double back slash (\\)
Again, thank you!!0 -
Glad to hear that you were able to make it work!
1