I am attempting to preform a Web Request GET but the source is responding with a html/text instead of a JSON. the $response variable seems to only accept JSON responses, is there another variable that I’m missing?
HTTP Web Requests
I tried a web request with an endpoint that returns HTML and $response contained that HTML. Is it possible that the endpoint is misconfigured and responding with mismatched content type (i.e. the response says it is JSON so webCoRE tries to parse it as JSON, but it’s actually HTML)? Might be able to help if this is a public service that I can try out on my end.
I think you may be correct! The endpoint is saying that it puts out JSON but when pulling it in to a browser it looks like its a jumbled mess of HTML, is there a way for webCoRE to force it? I dont mind which it returns. Either way I just want to search to see if a particular word is in the response or not.
You’ll need to check documentation on the endpoint, sometimes you’ll see a parameter like &format=html
to control the response format while other services may expect an Accept
header to specify the response format.
Can you explain what you’re seeing in webCoRE more concretely? What is the value of $response
and does the expression $response.data
show an error like Error retrieving JSON data part null? You should be able to use $response
(e.g. if contains($response, 'target text') then...
) with any response. If the request is not successful (i.e. not a 200
response status code) then $response
will be null; webCoRE does not allow access to response data for error responses.
You can check the $httpStatusCode
and $httpContentType
variables for more insight.
The endpoint seems to be sending back the following string instead of a neat looking JSON table.
{“Status”:“Not Ready Trouble”,“Color”:“Yellow”}
$httpStatusCode = 200
$httpContentType = null
$response = [ : ]
Could you share a sample piston? A private message to me is best if the request requires any API keys or similar that you can’t post publicly.
@ipaterson, I’m reviving this thread since my question is similar… is it possible to send an accept header
with a webcore request? I’m trying to send application/ld+json
with the request
Web requests may fail with 406 status code due to incorrect Accept header
No, you can’t send custom headers currently. There is a discussion of a possible way to support that here