I am running a simple GET request to query a single item of data which provides a response. When this happens, I want to send myself an email summarising my request and response. When I use a debug node to display the output, I get something that looks fine for my purposes such as this:
However, when I try to use this in the body of an email it looks horrid. It has the right information but mot nicely. Here’s what I use and get:
"message": "Request was {{responseUrl}}\nData logger response {{payload}}"
Request was http://ip:5782/datalogger?command=register&register=4&datalogger=logid
Data logger response {"value": "0.1"}
I’ve googled for ages but can’t find any way of getting better formatting. Any help very welcome.
I should of course have read the mustache manual but I still haven’t fully solved the problem. In theory, using {{{ item }}} should stop characters being escaped. This works with my url but doesn’t work with my payload. Trying that with the payload gives a runtime error as mustache seems to now think it has FOUR {! The manual suggests you can change the { character to something else using something like {{=<< >>=}}. However, this doesn’t work with the triple {{{ (I’ve tried {{{=<<<).
So I’ve got half a solution but not a whole one. Further suggestions welcome!
{
"message": "Request was http://ip:5782/datalogger?command=register®ister=4&datalogger=logid \nData logger response {\"value\":\"0.1\"}"
}
JSONata will return payload as {“value”: “0.1”}, but the string concatenator “&” stringifys the object first, inserting \ to escape the "s and maintain string structure.
The \n is a questionable addition to the string since this is only recognised in certain places. I am even having problems writing this in the forum editor as \" requires a \\ before the " and \\ requires \\\ (which is actually 5 of them). Perhaps payload.value, which returns 0.1 would be simpler.