I'm trying to access the Octopus Energy API to grab the current rate for a given time, a working example URL is:
Even this:
"curl https://api.octopus.energy/" from the command line eturns a formatted response if but fails in my script.
If relevant - HS is running on Windows 7 32bit.
https://developer.octopus.energy/docs/api/
I've tried the built-in hs.urlaction/geturl and the .net methods and they both fail:
Throws this:
Throws:
Code:
https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=2020-02-06T22:30:00Z&period_to=2020-02-06T22:35:00Z
Even this:
"curl https://api.octopus.energy/" from the command line eturns a formatted response if but fails in my script.
If relevant - HS is running on Windows 7 32bit.
https://developer.octopus.energy/docs/api/
I've tried the built-in hs.urlaction/geturl and the .net methods and they both fail:
Code:
Sub Main(parm as object) Dim Period_from As String Period_from = (System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK")) Dim Period_to As String Dim response As String Period_to = (System.DateTime.UtcNow.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ssK")) 'Built URL based on the time now. 'Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=" & Period_from & "&period_to=" & Period_to 'example of a working URL: 'Dim requestUrl As String = "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-B/standard-unit-rates/?period_from=2020-02-06T22:30:00Z&period_to=2020-02-06T22:35:00Z" 'very simple request that should return "not found" Dim requestUrl As String = "https://api.octopus.energy/" ' response = hs.URLAction(requestUrl, "GET", "", "Content-Type: text/plain") hs.WriteLog("response:", response) End Sub
Feb-15 14:45:23 | response: | The underlying connection was closed: An unexpected error occurred on a send. |
Feb-15 14:45:23 | Error | In URLAction GET: The underlying connection was closed: An unexpected error occurred on a send. |
Code:
Imports System.Convert Imports System.IO Imports System.Net Public Sub Main(ByVal Parms As Object) Try Dim myWebRequest As WebRequest = WebRequest.Create("https://api.octopus.energy") ' Send the 'WebRequest' and wait for response. Dim myWebResponse As WebResponse = myWebRequest.GetResponse() Catch ex As Exception : hs.WriteLog("Error: ", ex.Message.ToString) End Try End Sub
Feb-15 14:47:42 | Error: | The underlying connection was closed: An unexpected error occurred on a send. |
Comment