0

Not able to connect to http API

Joachim 2 years ago in Devices / Http updated 2 years ago 11

Hi,

I'm trying to fetch energy prices from a public available API with a JSON array.

The data I'm trying to get can be found in this link:

GET https://www.hvakosterstrommen.no/api/v1/prices/2022/10-02_NO5.json

I have tried to play around with the url with different parts in the http settings and in the command settings. Anyone able to make this work?

Image 4113

It works for me. I got response from it and it stays connected. How did you add it to bos?


First add the http driver. Then first part of the link add here: 

Then add the command to same driver and last part of the link paste in the command line:


Then you can send the request and it should update with status code OK:

That is strange. When I try, it just comes back with "Error connecting to device". I tried to make a new HTTP device and add the data exactly as you showed.

+1

Kodu-Http hvakosterstrommen.no.bos

Well im not sure whats wrong with it then - here is my test template for it. Maybe it helps.

Thanks a lot.
I have now tried your template on two different Jigsaw servers on two different physical locations. One with version 4.9.8 and the other with version 4.9.17. None of them works for me.

Then I'm out of ideas...

I'm realising that even if I get this to work I will have problems sending correct commands to the API.

Time and date values from bOS is 1-digit from 0-9 and the API requires 2 digits. E.g. 01, 02, 03 etc.

Any ideas on how to get around this?

Edit: Found a solution for this using program task and "string" instead of "double" 👍

Yeah calculating dates is a problem. I'm having same issues, and so far there isnt a good way to calculate dates imo. Adding the 0 IN front of single digit dates isn't a huge problem as you can make programs for it, check my Elering api template and you will see how i did it there. 
My main problem is with end and start of the month - If the month has less than 31 days the programs will not work as they still calculate dates/months as there was 31 days. 
I've asked bOS support if they can add some more date values in bOS Time - so it has dedicated values for yesterday, today and tomorrow. This would make calculating them easier.

Double should work too. use Token name: .Array[0].EUR_per_kWh or .Array[0].NOK_per_kWh to get the first value - change the number [0] 0-23 to get other values.

OK, so for the "fun of it", I installed the server on my windows computer, restored my latest Jigsaw backup and added the http driver. Works like a charm.
Seems like it somehow is related to the Jigsaw's. Bug perhaps? I will create a ticket in the support system

+1

I can confirm that on Jigsaw the command doesn't work, it shows "Error connecting to device", as stated by Joachim.

Running 4.9.17 on Jigsaw.

Best regards

Yeah seems like there is a problem with jigsaw's http driver. Sadly I updated mine today to 4.9.17, so i'm not sure if older bos versions are still working.
Also my elering api template is not working on jigsaw anymore - But weather's api and publick ip api's are still working. 

Thanks guys. I have created a support ticket. Hopefully it will be fixed soon 🤞