REST API Text body with "\n"
Question

Hello Guru's

I'm consuming a rest API and there I have to send some text with \n.

When I look at the OnBeforeRequest the body is escaped and the \n is now \\n

The server there for is giving me a error because they want to receive it like \n

I also tried it manually from service studio and then it works.


Hope to get some help. 

Solution that I now have is to add a 

Replace(CustomizedRequest.RequestText,"\\","\")

On the OnBeforeRequest and that works.

Hello,

If I understood you question properly you want to separte your text with a line breaker.
Have you tried to use the system function NewLine() for this purpose?
Documentation available here.


Otherwise the platform will threat it as a text and escape special characters like the "\".


Best regards,
Paulo Jadaugy


I have a piece of code in the database like: lkasdlkd\nlksdflkadslk\nasdfasdf

This needs to be send to the exposer of the REST Api.


Hi,

If you want to send that exact text using JSON it needs to be escaped otherwise that it would be like sending something like this:

More details:

This is for JSON format, for XML it's also a reserved word the character "\".
I'm glad to hear that you were able to solve your issue doing a replace on the request text.


Regards,
Paulo Jadaugy

The Rest service that I call is for exchanging RSA keys and they NEED the \n in the text that I can't change.

So probably only my solution by replacing the \\ is working?

Hi,

Yes, as far as I'm aware the platform will always try to escape the content of the text sent to make sure it's valid (hence the double \), so we would need to unescape by removing one \.

Best regards,
Paulo Jadaugy

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.