[SalesForce] Callout response: Illegal character sequence in string literal

I got a problem that is driving me crazy. Hopefully you guys can help:

I am trying to integrate the eKomi Api.

For this I am doing a callout which returns the response System.HttpResponse[Status=OK, StatusCode=200]. So everything seems fine.

However, when I try to debug the body via getBody(), I get the following error message:

FATAL_ERROR|System.CalloutException: Could not parse HTTP response body to string

When I enter the callout in my browser, I receive the following response:

{"link":"https:\/\/www.ekomi.de\/kundenmeinung.php?kunde=customerId&shop=shopId","hash":"hash","known_since":"2017-07-24","done":1,"done_at":1500974822}

When I try to debug this String, I get the following error message upon deploy:

Validation Failed
ERROR validating ApexClass classes/SendEkomiReviewRequest.cls: Invalid string literal '{"link":"https://www.ekomi.de/kundenmeinung.php?kunde=customerId&shop=shopId","hash":"hash","known_since":"2017-07-24","done":1,"done_at":1500974822}'. Illegal character sequence '/' in string literal.

The problem is that I can't change what's in the response. As the validation of the string fails, I can neither remove nor replace the illegal character sequence.

Do you have any idea what to do here? I'm desperate for any ideas.

Thanks a lot
Daniel

Best Answer

Have you tried going via a Blob?

getBodyAsBlob().toString() 

No idea if that will actually work but you have a pretty odd case here!

(Turns out that this worked, so submitted as an answer instead of a comment)

I don't know why it works, I'd guess that SF is trying to parse the raw http response in the getBody() version and getting it wrong. Or perhaps the API is returning something that isn't quite valid. Not sure, really.