# Solcast API GET returns html

**URL:** https://discourse.nodered.org/t/solcast-api-get-returns-html/58855
**Category:** Dashboard
**Created:** [23 February 2022 02:10 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855 "2022-02-23T02:10:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![trialnerror](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@trialnerror](https://discourse.nodered.org/u/trialnerror)
#### Post date: [23 February 2022 02:10 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855/1 "2022-02-23T02:10:46Z")

</div>

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=](https://api.solcast.com.au/rooftop_sites/xxxx-xxxx-xxxx-xxxx/forecasts?format=json%E2%80%8B&hours=48&api_key=){API KEY}  
where xxxx is my site ID and {API KEY} is my personal key.

```auto
[
    {
        "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:

```auto
<!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:

```auto
{"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

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [23 February 2022 08:32 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855/2 "2022-02-23T08:32:01Z")

</div>

> [@trialnerror](#):
>
> If I put the same request into my browser I get:

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](https://cookbook.nodered.org/http/set-request-header) for how to add headers to a request.

---

<div class="post-metadata">

### Author: ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)
#### Post date: [23 February 2022 10:26 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855/3 "2022-02-23T10:26:07Z")

</div>

```auto
[{"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.

---

<div class="post-metadata">

### Author: ![trialnerror](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@trialnerror](https://discourse.nodered.org/u/trialnerror)
#### Post date: [23 February 2022 10:50 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855/4 "2022-02-23T10:50:18Z")

</div>

> [@Urs-Eppenberger](#):
>
> `[{"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',\"kr4xxxxx9cMrToNnYNs0yZkTMHsQ-h4J\");\nflow.set('ressourceID',\"1bxx-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"]]}]`

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!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 March 2022 10:50 UTC](https://discourse.nodered.org/t/solcast-api-get-returns-html/58855/5 "2022-03-09T10:50:44Z")

</div>

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