Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api_params with GET type retrievals don't work #13

Open
BramVan-Oosterhout opened this issue Nov 9, 2023 · 0 comments
Open

api_params with GET type retrievals don't work #13

BramVan-Oosterhout opened this issue Nov 9, 2023 · 0 comments

Comments

@BramVan-Oosterhout
Copy link

Hi Steve,
Thanks for a useful interface. I am using it to get data from a Powerwall. In particular the timeseries at the CALENDAR_HISTORY_DATA endpoint.

The Tesla::API returns some current day data when when called without parameters. But the unofficial documentation at https://tesla-api.timdorr.com/energy-products/energy/history allows parameters to select the date for the timeseries can be supplied. So I issued the following call:


  my $timeseries =  $tesla->api(
                endpoint => $config->{power}{endpoint},
                id => $config->{powerwall}{id},
                api_params => \%params
                );

But the returned timeseries remained for the current day

I spent some time in the debugger and noticed the parameters are added as json to the header data. Which made me think that the request is assumed to be a POST. The documentation asserts the type is GET. With that assumption I hacked API.pm adding:

sub fixUriGetWithParam {
  my ( $uri, $params ) = @_;
  my $connect = '?';
  foreach my $p ( keys %$params ) {
    $uri .= $connect . $p . '=' . $params->{$p};
    $connect = '&';
  }
  return $uri; 
}

and calling the routine before line 122 my $url = $self->uri(URL_API . $uri); with:

    $uri = fixUriGetWithParam( $uri, $api_params )
        if $type eq 'GET' && $api_params;

I now retrieve data for a requested date. So the change addresses my issue. However, I have no idea whether this is a sane solution to the problem. I do not understand the internals of Http::Request etc.

If this approach is sane, I am happy to supply a pull request. If it is not, I am open to alternatives and implement these.

Let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant