# Http requests for json

**URL:** <https://community.homey.app/t/http-requests-for-json/71379>\
**Category:** Developers\
**Created:** [October 29, 2022, 3:55pm UTC](https://community.homey.app/t/http-requests-for-json/71379 "2022-10-29T15:55:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_Alford](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neil_alford/32/37373_2.png) [@Neil\_Alford](https://community.homey.app/u/Neil_Alford)\
**Post date:** [October 29, 2022, 3:55pm UTC](https://community.homey.app/t/http-requests-for-json/71379/1 "2022-10-29T15:55:43Z")

</div>

Hi,

hoping someone a bit more knowledgeable might be able to offer some suggestions on what I might be doing wrong in the Homey app I’m writing. Basically I’m trying to get some json data from a Solar Battery inverter via its API, however I instead seem to be receiving some html data instead. My code is as follows (except with and having the correct values):

```auto
'use strict';

var http = require('http');

const Homey = require('homey');

var options = {
  host: 'api.givenergy.cloud',
  path: '/v1/inverter/<SERIAL NUMBER>/system-data/latest/',
  method: 'GET',
  headers: {'Authorization': 'Bearer <API KEY>',
  'Content-Type': 'application/json',
  'Accept': 'application/json'}
};

class GivEnergy extends Homey.App {

  callback = function(response) {
    console.log('Callback');
    var str = '';
    response.on('data', function (chunk) {
      str += chunk;
    });

    response.on('end', function() { 
      console.log(str);
    });

    //var jsonObject = JSON.parse(str);
  }

  async onInit() {
    this.log('GivEnergy has been initialized');

    var req = http.request(options, this.callback);
    req.end();

    this.log('End');
  }
}
module.exports = GivEnergy;

```

It is based on this Powershell script (which returns the correct data):

```auto
$headers_Giv_En = @{
 'Authorization'="Bearer $GivEnergyPortalAPI"
 'Content-Type'='application/json'
 'Accept'='application/json'
 }
$Giv_En = Invoke-RestMethod -Method 'Get' -Uri https://api.givenergy.cloud/v1/inverter/$SerialNum/system-data/latest/ -Headers $headers_Giv_En
$Giv_En | ConvertTo-Json -Depth 10 | Out-File -FilePath .\InvData_Now.txt -Encoding ASCII

Write-Output "Data Saved to: InvData_Now.txt"
Write-Output "All done - Exit in 5...." 
start-sleep -s 5

Exit

```

I suspect maybe it is something to do with the header data, but that looks correct to me. Does anyone have any suggestions? I’m fairly new to Javascript.

---

<div class="post-metadata">

**Author:** ![spkesDE](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/spkesde/32/54352_2.png) [@spkesDE](https://community.homey.app/u/spkesDE)\
**Post date:** [October 29, 2022, 4:28pm UTC](https://community.homey.app/t/http-requests-for-json/71379/2 "2022-10-29T16:28:58Z")

</div>

Could give us an example to what outputs both code snipping gives?  
Maybe the cloud doesn’t accept http. use require(‘https’) instead

Also check the status code of the response. `response.statusCode`  
200, 201 is ok, everything else is usually bad.

---

<div class="post-metadata">

**Author:** ![Neil\_Alford](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neil_alford/32/37373_2.png) [@Neil\_Alford](https://community.homey.app/u/Neil_Alford)\
**Post date:** [October 30, 2022, 9:35am UTC](https://community.homey.app/t/http-requests-for-json/71379/3 "2022-10-30T09:35:02Z")

</div>

Thanks, you were right, the issue was the use of http rather than https. So it was returning a status code of 301 indicating a redirect to the https version and the data returned was html redirection code.

---

<div class="post-metadata">

**Author:** ![Welshsmarthome](https://avatars.discourse-cdn.com/v4/letter/w/df705f/32.png) [@Welshsmarthome](https://community.homey.app/u/Welshsmarthome)\
**Post date:** [October 15, 2025, 9:27pm UTC](https://community.homey.app/t/http-requests-for-json/71379/4 "2025-10-15T21:27:18Z")

</div>

Have you got this working?

---

<div class="post-metadata">

**Author:** ![Neil\_Alford](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neil_alford/32/37373_2.png) [@Neil\_Alford](https://community.homey.app/u/Neil_Alford)\
**Post date:** [October 16, 2025, 7:22am UTC](https://community.homey.app/t/http-requests-for-json/71379/5 "2025-10-16T07:22:10Z")

</div>

Yes, as mentioned it was simply because I was including http rather than https, as far as I remember. Once that was fixed I was able to connect to the API as expected.

---

<div class="post-metadata">

**Author:** ![Welshsmarthome](https://avatars.discourse-cdn.com/v4/letter/w/df705f/32.png) [@Welshsmarthome](https://community.homey.app/u/Welshsmarthome)\
**Post date:** [January 15, 2026, 10:35pm UTC](https://community.homey.app/t/http-requests-for-json/71379/6 "2026-01-15T22:35:21Z")

</div>

How is this working in Homey? Can you set flows to control battery or link solar to Insights?  
Thanks

---

<div class="post-metadata">

**Author:** ![Neil\_Alford](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neil_alford/32/37373_2.png) [@Neil\_Alford](https://community.homey.app/u/Neil_Alford)\
**Post date:** [January 16, 2026, 1:07pm UTC](https://community.homey.app/t/http-requests-for-json/71379/7 "2026-01-16T13:07:01Z")

</div>

Yes, I’ve got insights working and control of the battery via flows, so I have a flow set up that checks the battery level in the evening and discharges excess to the grid before my cheap rate begins. I’m planning on tidying it up a bit and improving it (currently it doesn’t create proper devices just runs as an app) then might consider releasing it as a community project. It’s far from perfect, i.e. it works via the web portal rather than using the local network but after a bit of tweaking it seems to work reasonably reliably.

---

<div class="post-metadata">

**Author:** ![Jak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jak/32/157314_2.png) [@Jak](https://community.homey.app/u/Jak)\
**Post date:** [March 9, 2026, 12:04pm UTC](https://community.homey.app/t/http-requests-for-json/71379/8 "2026-03-09T12:04:08Z")

</div>

Hey

I’ve got a GivEnergy app in development. It’s using the local network (via modbus) rather than cloud API.

I’m looking for people to help test it out on different installations. If you’re interested, please get in touch!

 ![E2EBDD11-383C-4825-926B-A50279C78BE5_4_5005_c](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/6/36d5194665ef390f974ae6a4b35b081805576398.jpeg)

---

<div class="post-metadata">

**Author:** ![Neil\_Alford](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neil_alford/32/37373_2.png) [@Neil\_Alford](https://community.homey.app/u/Neil_Alford)\
**Post date:** [March 11, 2026, 10:04am UTC](https://community.homey.app/t/http-requests-for-json/71379/9 "2026-03-11T10:04:31Z")

</div>

Hi,

I could be interested in testing, the use of MODBUS is definitely interesting and something I’d hoped to one day add to my app.

I’m running a GivEnergy 3KW AC Inverter with a single gen1 8.2KWh battery, alongside a separate Growatt inverter for my panels.

I have an Original Homey and a Homey Pro.

---

<div class="post-metadata">

**Author:** ![Jak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jak/32/157314_2.png) [@Jak](https://community.homey.app/u/Jak)\
**Post date:** [March 11, 2026, 11:22am UTC](https://community.homey.app/t/http-requests-for-json/71379/10 "2026-03-11T11:22:05Z")

</div>

Great to hear!

The test version of app is here: [GivEnergy | Homey](https://homey.app/en-gb/app/io.jak.givenergy/GivEnergy/test/)

I’m gathering feedback on this topic: [[APP][Pro] GivEnergy](https://community.homey.app/t/app-pro-givenergy/152231)

That’s quite a different setup from mine (gen 3) so how well it works would be interesting for me to learn. Thank you.
