Bearer Authentication in httpget

I am trying to write a driver to collect data from the Tigo Energy solar system APIs. As a starting point I am using the Solar Edge driver written by @funzie

Tigo Energy uses bearer authentication. I have my token and it works successfully with the following Curl command:

curl -v "https://api2.tigoenergy.com/api/v3/data/summary?system_id=1111" -H "Authorization: Bearer XXXX"

(Note: I've redacted my actual system ID and bearer token)

I've tweaked the "httpcode" to read as follows:

    def params = [
    uri: "https://api2.tigoenergy.com/api/v3/data/summary?system_id=1111",
    header: "Authorization: Bearer XXXX"
        ]
httpGet( params) { r ->
      def meters = r.data.energyDetails.meters
...

I get this error: errorgroovy.lang.MissingMethodException: No signature of method: java.lang.IllegalArgumentException.getStatusCode() is applicable for argument types: () values: [] on line 412 (method getEnergy)

While I've done a lot of programming in the past, I am new to the Go language and encoding things for HTTPS APIs.

Any help or pointers would be greatly appreciated!

Marc

Try it like this:

headers: [Authorization: "Bearer XXX"]

By the way, you didn't actually post the line that generated your exception. It looks like there's some error handing code for the request that isn't quite right.

@tomw thank you for your help! You were spot on in both of your observations. Between your points and an explanation I got from my friend I've made a ton of progress.

I am at the point where I am successfully getting the data back from Tigo, but when I do the "sendEvent" to update the value of the attribute I get this error: groovy.lang.MissingMethodException: No signature of method: com.hubitat.app.exception.LimitExceededException.

Below is the code I have as well as the logs. Any thoughts on what could be causing this problem?

Marc

Here is the code. The error happens at the "sendEvent".

def queryEnergyEndpoint() {
    
    if (debug) { log.debug "Gathering energy metrics." }

    def today =  timeToday("00:00").format("YYYY-MM-dd")
    def p_uri = "https://api2.tigoenergy.com/api/v3/data/summary?system_id=1111"
    def p_headers = [ "Authorization": "Bearer xxxx" ]
    
  try { 
    if (debug) log.debug "In try, executing httpget."
    httpGet( 
        uri: p_uri,
        headers: p_headers
    ) { r-> 
        def summary = r.data.summary
        if (debug) {
            log.debug("Made it")
            log.debug "Status: ${r.getStatus()}"
            log.debug "Headers: ${r.getAllHeaders()}"
            log.debug "Content Type: ${r.getContentType()}"
            log.debug "Response: ${r.data}"
            log.debug "summary: ${summary}"
        }
        def iproduction = summary.daily_energy_dc.toFloat().toInteger()
        log.debug("Converted integer value: $iproduction")
        if (debug) log.debug "production: ${summary.daily_energy_dc}"
        if (debug) log.debug "iproduction: $iproduction"
        sendEvent(name: "production", value: iproduction)
        log.debug "production event sent"
    }
  } catch (Exception e) {
    log.error "Exception"

    if(e.getStatusCode()) {
      switch(e.getStatusCode()) {
          case 401:
              log.error "401 - Not authorized"
              break
          case 403:
              log.error "403 - Forbidden"
              break
          case 429:
              log.error "429 - Too many requests"
              break
          default:
              log.error "Unkown Error"
              log.error "httpGet status code: e.getStatusCode ${e.getStatusCode()}"
              log.error "httpGet message: e.message : ${e.message}"
              log.error "httpGet full stack: e : ${e}"
              break
      }
    }
  }

Here are the logs


[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.180 PM[error](http://hubitathub.local/logs#)groovy.lang.MissingMethodException: No signature of method: com.hubitat.app.exception.LimitExceededException.getStatusCode() is applicable for argument types: () values: [] on line 381 (method getEnergy)

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.153 PM[error](http://hubitathub.local/logs#)Exception

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.150 PM[debug](http://hubitathub.local/logs#)iproduction: 52851

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.148 PM[debug](http://hubitathub.local/logs#)production: 52851.95

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.145 PM[debug](http://hubitathub.local/logs#)Converted integer value: 52851

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.142 PM[debug](http://hubitathub.local/logs#)summary: [lifetime_energy_dc:103106572.79363, ytd_energy_dc:8619390.36, daily_energy_dc:52851.95, last_power_dc:0, updated_on:2023-08-19T18:06:00-07:00]

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.140 PM[debug](http://hubitathub.local/logs#)Response: [summary:[lifetime_energy_dc:103106572.79363, ytd_energy_dc:8619390.36, daily_energy_dc:52851.95, last_power_dc:0, updated_on:2023-08-19T18:06:00-07:00]]

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.137 PM[debug](http://hubitathub.local/logs#)Content Type: application/json

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.134 PM[debug](http://hubitathub.local/logs#)Headers: [date: Sun, 20 Aug 2023 01:18:56 GMT, server: Apache, upgrade: h2, connection: Upgrade, access-control-allow-origin: *, access-control-allow-headers: *, Authorization, x-app-version, Content-Type, access-control-expose-headers: X-APP-HAS-UPDATE, vary: Accept,Accept-Encoding, x-rate-limit-limit: 1000, x-rate-limit-remaining: 999, x-rate-limit-reset: 3, access-control-allow-credentials: false, set-cookie: _csrf=xxxx; path=/; domain=.tigoenergy.com; secure; HttpOnly; SameSite=Lax, x-content-type-options: nosniff, x-frame-options: sameorigin, content-type: application/json; charset=UTF-8, strict-transport-security: max-age=63072000]

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.130 PM[debug](http://hubitathub.local/logs#)Status: 200

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:57.127 PM[debug](http://hubitathub.local/logs#)Made it

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:56.822 PM[debug](http://hubitathub.local/logs#)In try, executing httpget.

[dev:1785](http://hubitathub.local/logs#)2023-08-19 06:18:56.820 PM[debug](http://hubitathub.local/logs#)Gathering energy metrics.

How many times is this code getting executed ?

Hi @thebearmay, thank you for replying.

At this time, it only gets executes when I hit the "getEnergy" on the device, as I do not have it scheduled to auto-update.

The debug output is consistent with it only getting executed once/"hit".

Thanks!

Marc

A quick update.

When all else fails, reboot...

Things seem to be working now. Not sure why a reboot changed the outcome so profoundly, but I'll take it.

Thanks everyone for your help!

Marc

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