Solved Issue with HTTPBuilder
-
Hi, I'm currently trying to use the HttpBuilder in the scripting data source to get some data in JSON format, but I'm getting the error "Request got bad response: 400 in at line 35 at column number 8." I've tested the exact same URL and headers in Postman and had no problem retrieving the data, so I'm not quite sure what's going wrong here. This is what I've done so far: [phil removed image]
-
Hi jwang,
You could try pointing the HttpBuilder and Postman at a listening netcat or such, to see how the GET requests may differ. Alternatively you can print the headers and content in the error function to perhaps get a better idea of why it returned status 400.
I don't think this is the issue, but it looks like you've encoded the parameters of the get yourself. You could have placed these in the parameters object, and then they would have been added to the URL for you.
-
Possibly missing an
Accept: application/json
header? -
@phildunlap
Hi Phil,I tried printing out the headers and the content in the error function, and the header says "Server=nginx/1.14.0" while the content says '"message":"Not found: 400 Bad Request: The browser' so it doesn't look like there's any content at all.
I also encoded the parameters into the URL itself so that I could see the actual page that would result if we copy and paste the link into the browser: http://api-dev.hiqsolar.net/api/v1/inverters/data?gw_serial=2589&start_date=2019-07-15&fields=kwh&group=period&res=10m&inv_serial=16675
There's clearly data on the page, even without the headers involved, so I'm still not sure why the HTTP Builder isn't picking up that data from the URL. I've also tried Jared's recommendation by adding "Accept: application/json" as a header and that hasn't fixed it either. Do you happen to have any other ideas?
-
I should have added that the HttpBuilder is adding a
Content-Type: application/json
header if no Content-Type is supplied, which is probably a bad behavior for a GET. I would still suggest pointing these at a Linux system with a listening netcat, though, so that you could see exactly how the HTTP requests were differing.I was able to use that URL with a header of
Content-Type: text/plain
And oddly no API key required, but that probably means there's some limiter. You may want to remove the image from your initial post, since you included your API key and where it goes.
Edit: I have made it such that in the next version no Content-Type header will be added to GET requests if missing.