HTTP Request - response is null with HTTP 202 response


1) Give a description of the problem
I’m trying to interact with an external service (that I do not control) using an HTTP POST.

2) What is the expected behaviour?
I POST a request, the service responds with JSON encoded data (I’m pulling a URL from it).

3) What is happening/not happening?
The $response variable is null even though I’m expecting a body. Logging $httpStatusCode confirms I’m receiving a 202 Accepted, which is what I expect after a successful POST based on testing with Postman. $httpContentType comes back as text/json which I think is a bit odd but also correct based on Postman testing.

I think I read somewhere in a thread here that only a 200 response is accepted to populate $response? If that’s the case, I’d suggest that anything in the 200-series response codes should be accepted. Also that even a 400-series response might contain useful information in the returned body that we’d want to capture into $response.


I agree, only populating $response for status code 200 is wrong. There are certain status codes where attempting to read the body throws an exception, but 202 is not one of them. If you want a quick patch,
the line if ((response.status == 200) && && !binary) { in the webCoRE Piston smart app can be changed to if ((response.status < 300) && && !binary) {. I tested that tweak and a 202 works fine.

Any official change here will not include redirect and error status codes since people may have relied on $response == null to identify request failure.


Thanks for this! The simple modification noted did the trick to accept the response. Unfortunately it seems the server sending Content-Type text/json prevents me from extracting the JSON elements using $ so I had to resort to string processing.

For clarity, it sounds like you plan to apply this change to the piston code to accept anything in the 200 series? Only asking so I know if I need to re-patch my instance after updates.


It is committed for the next release so you will not need to patch anything going forward. Can you pass the response off to Parse JSON to access your response data more safely via $json?