Solcast API GET returns html

I'm not too sure where the problem lies with this one, but it seems to arise in Node-Red only so I'm asking here first.

Solcast API call should return JSON, but I seem to only get back html in NR.
My call is:
https://api.solcast.com.au/rooftop_sites/xxxx-xxxx-xxxx-xxxx/forecasts?format=json​&hours=48&api_key={API KEY}
where xxxx is my site ID and {API KEY} is my personal key.

[
    {
        "id": "8173ff729284cc7e",
        "type": "http request",
        "z": "acf06df9c6b509cc",
        "name": "Solcast forecast",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://api.solcast.com.au/rooftop_sites/xxxx-xxxx-xxxx-xxxx/forecasts?format=json​&hours=48&api_key={API KEY}",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "credentials": {},
        "x": 300,
        "y": 80,
        "wires": [
            [
                "55bbf03a32309649",
                "d0a58f1004ca461b",
                "76cb289f11212323"
            ]
        ],
        "info": ""
    }
]

I've also tried setting the return string to UTF-8.

The response I get is:

<!doctype html>
<html lang="en-us">
<head>
<title>GetRooftopSiteForecast Snapshot of 02/23/2022 01:27:06</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
BODY, H1, H2, H3, H4, H5, H6, DL, DT, DD {
  margin: 0;
  padding: 0;
  color: #444;
  font: 13px/15px Arial, Verdana, Helvetica;
}

If I pass the msg to a JSON node I get an error that the first character is <, which fits with it receiving html.

If I put the same request into my browser I get:

{"forecasts":[{"pv_estimate":4.6525,"pv_estimate10":3.9215,"pv_estimate90":5,"period_end":"2022-02-23T01:30:00.0000000Z","period":"PT30M"},{"pv_estimate":4.983,"pv_estimate10":4.1996,"pv_estimate90":5,"period_end":"2022-02-23T02:00:00.0000000Z","period":"PT30M"},{"pv_estimate":4.9969,"pv_estimate10":4.2031,"pv_estimate90":5,"period_end":"2022-02-23T02:30:00.0000000Z","period":"PT30M"},

Similarly if I use curl I get the expected json returned.

I've looked at a couple of other user's calls to solcast and they seem to be structured the same (I've imported their flows, copied the http node and edited it to my site and api key and get the same result).

So can anyone shed light on why NR is receiving html instead of json?
Thanks

Use your browsers developer tools console to inspect the working request (use the devtools network tab, refresh your browser, inspect the request and its headers).

I suspect you will find by adding the same headers to the http request node you will get the same result.

See the cookbook: Set a request header : Node-RED for how to add headers to a request.

[{"id":"44b73686.20b328","type":"function","z":"4e139d26.c717a4","name":"create request","func":"APIkey = flow.get('APIkey');\nvar auth = APIkey+':';\nmsg.ResourceID = flow.get('ressourceID');\nmsg.headers = {\n    \"Authorization\": 'Basic ' + new Buffer(auth).toString('base64')\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n\nflow.set('APIkey',\"kr4xMBTh9cMrToNnYNs0yZkTMHsQ-h4J\");\nflow.set('ressourceID',\"1bcd-81cf-8823-ac4f\");","finalize":"","libs":[],"x":340,"y":980,"wires":[["560ddd10.f28bfc","624210f6782e5609"]]},{"id":"560ddd10.f28bfc","type":"http request","z":"4e139d26.c717a4","name":"fetch solcast","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.solcast.com.au/rooftop_sites/{{{ResourceID}}}/forecasts?format=json","tls":"","persist":false,"proxy":"","authType":"","credentials":{},"x":540,"y":980,"wires":[["decd550.b8ce6a8","c1c7663590e07e5a"]]}]

This is how I do it. Maybe not the most elegant way, but it works.

Thank you.
That worked (after I corrected a typo in ressourceID - resourceID).
I don't understand entirely why this is different from just putting the same text in the URL, but I don't mind a bit of magic!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.