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

Endpoint is only available on fleetapi #3629

Closed
1 task done
bendavis78 opened this issue Jan 23, 2024 · 64 comments
Closed
1 task done

Endpoint is only available on fleetapi #3629

bendavis78 opened this issue Jan 23, 2024 · 64 comments
Labels
area:tesla api Related to the Tesla API note:help wanted Extra attention is needed note:needs investigation The issue must be investigated first

Comments

@bendavis78
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

I followed the docker instructions, and everything starts fine, but I'm just seeing a blank page on the home screen. There is no dashboard link in the main menu:

image

Expected Behavior

No response

Steps To Reproduce

No response

Relevant log output

[+] Running 4/0
 ✔ Container teslamate-database-1   Created                                                                                                  0.0s
 ✔ Container teslamate-grafana-1    Created                                                                                                  0.0s
 ✔ Container teslamate-mosquitto-1  Created                                                                                                  0.0s
 ✔ Container teslamate-teslamate-1  Created                                                                                                  0.0s
Attaching to database-1, grafana-1, mosquitto-1, teslamate-1
mosquitto-1  | 1705973491: mosquitto version 2.0.18 starting
mosquitto-1  | 1705973491: Config loaded from /mosquitto-no-auth.conf.
mosquitto-1  | 1705973491: Opening ipv4 listen socket on port 1883.
mosquitto-1  | 1705973491: Opening ipv6 listen socket on port 1883.
mosquitto-1  | 1705973491: mosquitto version 2.0.18 running
database-1   |
database-1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
database-1   |
database-1   | 2024-01-23 01:31:31.555 UTC [1] LOG:  starting PostgreSQL 15.5 (Debian 15.5-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
database-1   | 2024-01-23 01:31:31.555 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
database-1   | 2024-01-23 01:31:31.555 UTC [1] LOG:  listening on IPv6 address "::", port 5432
database-1   | 2024-01-23 01:31:31.560 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
database-1   | 2024-01-23 01:31:31.567 UTC [28] LOG:  database system was shut down at 2024-01-23 01:30:28 UTC
database-1   | 2024-01-23 01:31:31.575 UTC [1] LOG:  database system is ready to accept connections
grafana-1    | logger=settings t=2024-01-23T01:31:31.665719861Z level=info msg="Starting Grafana" version=10.1.2 commit=8e428858dd branch=HEAD compiled=2023-09-18T20:41:04Z
grafana-1    | logger=settings t=2024-01-23T01:31:31.665980019Z level=info msg="Config loaded from" file=/usr/share/grafana/conf/defaults.ini
grafana-1    | logger=settings t=2024-01-23T01:31:31.66599103Z level=info msg="Config loaded from" file=/etc/grafana/grafana.ini
grafana-1    | logger=settings t=2024-01-23T01:31:31.665995524Z level=info msg="Config overridden from command line" arg="default.paths.data=/var/lib/grafana"
grafana-1    | logger=settings t=2024-01-23T01:31:31.665999496Z level=info msg="Config overridden from command line" arg="default.paths.logs=/var/log/grafana"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666002956Z level=info msg="Config overridden from command line" arg="default.paths.plugins=/var/lib/grafana/plugins"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666006639Z level=info msg="Config overridden from command line" arg="default.paths.provisioning=/etc/grafana/provisioning"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666010117Z level=info msg="Config overridden from command line" arg="default.log.mode=console"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666013755Z level=info msg="Config overridden from Environment variable" var="GF_PATHS_DATA=/var/lib/grafana"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666017398Z level=info msg="Config overridden from Environment variable" var="GF_PATHS_LOGS=/var/log/grafana"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666020921Z level=info msg="Config overridden from Environment variable" var="GF_PATHS_PLUGINS=/var/lib/grafana/plugins"
grafana-1    | logger=settings t=2024-01-23T01:31:31.66602457Z level=info msg="Config overridden from Environment variable" var="GF_PATHS_PROVISIONING=/etc/grafana/provisioning"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666028136Z level=info msg="Config overridden from Environment variable" var="GF_ANALYTICS_REPORTING_ENABLED=false"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666032748Z level=info msg="Config overridden from Environment variable" var="GF_SECURITY_ADMIN_USER=admin"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666036351Z level=info msg="Config overridden from Environment variable" var="GF_SECURITY_ADMIN_PASSWORD=*********"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666040313Z level=info msg="Config overridden from Environment variable" var="GF_SECURITY_DISABLE_GRAVATAR=true"
grafana-1    | logger=settings t=2024-01-23T01:31:31.66604438Z level=info msg="Config overridden from Environment variable" var="GF_SECURITY_ALLOW_EMBEDDING=true"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666048034Z level=info msg="Config overridden from Environment variable" var="GF_SECURITY_ANGULAR_SUPPORT_ENABLED=true"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666051789Z level=info msg="Config overridden from Environment variable" var="GF_USERS_ALLOW_SIGN_UP=false"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666055692Z level=info msg="Config overridden from Environment variable" var="GF_AUTH_ANONYMOUS_ENABLED=false"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666059386Z level=info msg="Config overridden from Environment variable" var="GF_AUTH_BASIC_ENABLED=false"
grafana-1    | logger=settings t=2024-01-23T01:31:31.666063298Z level=info msg=Target target=[all]
grafana-1    | logger=settings t=2024-01-23T01:31:31.66607299Z level=info msg="Path Home" path=/usr/share/grafana
grafana-1    | logger=settings t=2024-01-23T01:31:31.666076553Z level=info msg="Path Data" path=/var/lib/grafana
grafana-1    | logger=settings t=2024-01-23T01:31:31.666079854Z level=info msg="Path Logs" path=/var/log/grafana
grafana-1    | logger=settings t=2024-01-23T01:31:31.666083055Z level=info msg="Path Plugins" path=/var/lib/grafana/plugins
grafana-1    | logger=settings t=2024-01-23T01:31:31.666086669Z level=info msg="Path Provisioning" path=/etc/grafana/provisioning
grafana-1    | logger=settings t=2024-01-23T01:31:31.666090284Z level=info msg="App mode production"
grafana-1    | logger=sqlstore t=2024-01-23T01:31:31.666310546Z level=info msg="Connecting to DB" dbtype=sqlite3
grafana-1    | logger=migrator t=2024-01-23T01:31:31.696912109Z level=info msg="Starting DB migrations"
grafana-1    | logger=migrator t=2024-01-23T01:31:31.704887354Z level=info msg="migrations completed" performed=0 skipped=493 duration=494.056µs
grafana-1    | logger=secrets t=2024-01-23T01:31:31.705817879Z level=info msg="Envelope encryption state" enabled=true currentprovider=secretKey.v1
grafana-1    | logger=local.finder t=2024-01-23T01:31:31.757048459Z level=warn msg="Skipping finding plugins as directory does not exist" path=/usr/share/grafana/plugins-bundled
grafana-1    | logger=query_data t=2024-01-23T01:31:31.759625064Z level=info msg="Query Service initialization"
grafana-1    | logger=live.push_http t=2024-01-23T01:31:31.762554483Z level=info msg="Live Push Gateway initialization"
teslamate-1  | 2024-01-23 01:31:33.626 [info] Migrations already up
grafana-1    | logger=infra.usagestats.collector t=2024-01-23T01:31:34.27571016Z level=info msg="registering usage stat providers" usageStatsProvidersLen=2
grafana-1    | logger=modules t=2024-01-23T01:31:34.275966564Z level=info msg=initialising module=http-server
grafana-1    | logger=modules t=2024-01-23T01:31:34.27623594Z level=info msg=initialising module=secret-migrator
grafana-1    | logger=http.server t=2024-01-23T01:31:34.27793563Z level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl= socket=
grafana-1    | logger=modules t=2024-01-23T01:31:34.296820771Z level=info msg=initialising module=provisioning
grafana-1    | logger=provisioning.alerting t=2024-01-23T01:31:34.357946074Z level=info msg="starting to provision alerting"
grafana-1    | logger=provisioning.alerting t=2024-01-23T01:31:34.357963236Z level=info msg="finished to provision alerting"
grafana-1    | logger=modules t=2024-01-23T01:31:34.35803445Z level=info msg=initialising module=background-services
grafana-1    | logger=modules t=2024-01-23T01:31:34.358303078Z level=info msg="All modules healthy" modules="[http-server secret-migrator provisioning background-services]"
grafana-1    | logger=ngalert.state.manager t=2024-01-23T01:31:34.35837345Z level=info msg="Warming state cache for startup"
grafana-1    | logger=grafanaStorageLogger t=2024-01-23T01:31:34.359473993Z level=info msg="storage starting"
grafana-1    | logger=ngalert.state.manager t=2024-01-23T01:31:34.390561782Z level=info msg="State cache has been initialized" states=0 duration=32.184724ms
grafana-1    | logger=ngalert.scheduler t=2024-01-23T01:31:34.392336344Z level=info msg="Starting scheduler" tickInterval=10s
grafana-1    | logger=ticker t=2024-01-23T01:31:34.392396177Z level=info msg=starting first_tick=2024-01-23T01:31:40Z
grafana-1    | logger=ngalert.multiorg.alertmanager t=2024-01-23T01:31:34.392409252Z level=info msg="Starting MultiOrg Alertmanager"
grafana-1    | logger=grafana.update.checker t=2024-01-23T01:31:34.426574247Z level=info msg="Update check succeeded" duration=68.388542ms
grafana-1    | logger=plugins.update.checker t=2024-01-23T01:31:34.507538281Z level=info msg="Update check succeeded" duration=147.973255ms
teslamate-1  | 2024-01-23 01:31:35.703 [info] System Info: Erlang/OTP 26 (jit)
teslamate-1  | 2024-01-23 01:31:35.703 [info] Version: 1.28.2
teslamate-1  | 2024-01-23 01:31:36.176 [info] POST https://auth.tesla.com/oauth2/v3/token -> 200 (438.636 ms)
teslamate-1  | 2024-01-23 01:31:36.176 [info] Refreshed api tokens
teslamate-1  | 2024-01-23 01:31:36.183 [info] Scheduling token refresh in 6 h
teslamate-1  | 2024-01-23 01:31:36.184 [info] Running TeslaMateWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
teslamate-1  | 2024-01-23 01:31:36.185 [info] Access TeslaMateWeb.Endpoint at http://localhost
teslamate-1  | 2024-01-23 01:31:36.488 [info] GET https://owner-api.teslamotors.com/api/1/vehicles -> 412 (303.122 ms)
teslamate-1  | 2024-01-23 01:31:36.489 [warning] TeslaApi.Error / %{"error" => "Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info", "error_description" => "", "response" => nil}
teslamate-1  | 2024-01-23 01:31:36.489 [warning] Could not get vehicles: :unknown
mosquitto-1  | 1705973496: New connection from 172.18.0.3:50218 on port 1883.
mosquitto-1  | 1705973496: New client connected from 172.18.0.3:50218 as TESLAMATE_302E3534353 (p2, c1, k60).
teslamate-1  | 2024-01-23 01:31:36.496 [info] MQTT connection has been established
teslamate-1  | 2024-01-23 01:31:43.752 [info] GET /
teslamate-1  | 2024-01-23 01:31:43.756 [info] Sent 200 in 3ms
teslamate-1  | 2024-01-23 01:32:00.728 [info] GET /
teslamate-1  | 2024-01-23 01:32:00.734 [info] Sent 200 in 5ms
teslamate-1  | 2024-01-23 01:32:01.936 [info] GET /
teslamate-1  | 2024-01-23 01:32:01.940 [info] Sent 200 in 4ms
teslamate-1  | 2024-01-23 01:32:03.401 [info] GET /
teslamate-1  | 2024-01-23 01:32:03.407 [info] Sent 200 in 5ms
grafana-1    | logger=infra.usagestats t=2024-01-23T01:33:31.375308762Z level=info msg="Usage stats are ready to report"
database-1   | 2024-01-23 01:36:31.666 UTC [26] LOG:  checkpoint starting: time
database-1   | 2024-01-23 01:36:32.195 UTC [26] LOG:  checkpoint complete: wrote 8 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.512 s, sync=0.007 s, total=0.530 s; sync files=4, longest=0.004 s, average=0.002 s; distance=19 kB, estimate=19 kB

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

latest

@cwanja
Copy link
Collaborator

cwanja commented Jan 23, 2024

database-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization

Did you previously have an installation? It looks like there might be something lingering with a previous installation or similar volume name. Try destroying all the containers and volumes and restart fresh.

teslamate-1  | 2024-01-23 01:31:36.489 [warning] TeslaApi.Error / %{"error" => "Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info", "error_description" => "", "response" => nil}
teslamate-1  | 2024-01-23 01:31:36.489 [warning] Could not get vehicles: :unknown

This is alarming, but we shall see what happens @JakobLichterfeld @jsight @brianmay

@brianmay
Copy link
Collaborator

brianmay commented Jan 23, 2024

It does seem like the Tesla owner API has rejected the request to list the vehicles.

teslamate-1  | 2024-01-23 01:31:36.488 [info] GET https://owner-api.teslamotors.com/api/1/vehicles -> 412 (303.122 ms)
teslamate-1  | 2024-01-23 01:31:36.489 [warning] TeslaApi.Error / %{"error" => "Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info", "error_description" => "", "response" => nil}
teslamate-1  | 2024-01-23 01:31:36.489 [warning] Could not get vehicles: :unknown

The error would imply that this is due to the API changes, but isn't possible to be sure. It could be something else going wrong at the Tesla server also.

For the record, I don't seem to be getting these errors myself. Although maybe this only happens when restarting Teslamate. Do I dare try restarting it...

I guess I should try doing a manual request to that API.

@brianmay
Copy link
Collaborator

Sorry, never meant to close this.

@brianmay brianmay reopened this Jan 23, 2024
@brianmay
Copy link
Collaborator

This does not look good, I think I am getting the same error, from manual calls. Probably means if I restart teslamate, it will stop working. As the very first thing teslamate does is call this API to get the vehicle id and streaming id values.

curl -v --header 'Content-Type: application/json' \  --header "Authorization: Bearer $(pass show tesla/access_token)" \
  'https://owner-api.teslamotors.com/api/1/vehicles'

*   Trying 52.12.169.42:443...
* Connected to owner-api.teslamotors.com (52.12.169.42) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
*  subject: C=US; ST=California; L=Palo Alto; O=Tesla, Inc.; CN=owner-api.teslamotors.com
*  start date: May 16 00:00:00 2023 GMT
*  expire date: May 15 23:59:59 2024 GMT
*  subjectAltName: host "owner-api.teslamotors.com" matched cert's "owner-api.teslamotors.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://owner-api.teslamotors.com/api/1/vehicles
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: owner-api.teslamotors.com]
* [HTTP/2] [1] [:path: /api/1/vehicles]
* [HTTP/2] [1] [user-agent: curl/8.4.0]
* [HTTP/2] [1] [accept: */*]
* [HTTP/2] [1] [content-type: application/json]
* [HTTP/2] [1] [authorization: Bearer <censored> GET /api/1/vehicles HTTP/2
> Host: owner-api.teslamotors.com
> User-Agent: curl/8.4.0
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer <censored>
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
< HTTP/2 412
< x-xss-protection: 1; mode=block
< x-txid: <censored>
< content-type: application/json; charset=utf-8
< vary: Accept
< x-request-id: <censored>
< content-length: 143
< x-envoy-upstream-service-time: 21
< x-frame-options: DENY
< x-content-type-options: nosniff
< strict-transport-security: max-age=31536000; includeSubDomains
< cache-control: no-cache, no-store, private, s-max-age=0
< date: Tue, 23 Jan 2024 06:56:09 GMT
< server: envoy
<
* Connection #0 to host owner-api.teslamotors.com left intact
{"response":null,"error":"Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info","error_description":""}%                            

On the positive side, I think that the vehicle_data API might still be working (for how much longer I wonder?), and streaming is still working (my car currently asleep; am getting 408 errors which looks hopeful).

So if you know the vehicle id an and streaming id values, it might be possible to hack something together that bypasses the list vehicles call. Possibly other fields might also be important, e.g. name of car, not sure.

@JakobLichterfeld JakobLichterfeld changed the title Blank home page, no dashboards on new install Endpoint is only available on fleetapi Jan 23, 2024
@JakobLichterfeld JakobLichterfeld added note:help wanted Extra attention is needed note:needs investigation The issue must be investigated first area:tesla api Related to the Tesla API labels Jan 23, 2024
@fvillart
Copy link

@fvillart
Copy link

@lotharbach
Copy link

lotharbach commented Jan 23, 2024

I am reasonably sure the Tesla App is looking up the list of vehicles (and maybe other products) like this, as this is the only request I logged that contains both VIN and the ID:

curl -v --header 'Content-Type: application/json' --header "Authorization: Bearer $TOKEN" 'https://owner-api.teslamotors.com/api/1/products?orders=true'

It returns a json list, I only have one vehicle and can then see the numeric ID '.response[0].id' (and vin '.response[0].vin') to craft a vehicle_data request.

The Tesla App itself is still fetching vehicle_data every few seconds, so I think changing the way to fetch the list of vehicles will be sufficient for a while still.

@brianmay
Copy link
Collaborator

Yes, you are right, that does appear to be giving me good data. Wonder for long long...

@brianmay
Copy link
Collaborator

I think the current code passes the token as a query parameter. If I am reading this correctly. Will need to change that to pass the Authorization head instead.

(I tried passing it as a query parameter manually, it didn't seem to work).

Anyway, this code needs updating:

def list(%Auth{} = auth) do
endpoint_url =
case Auth.region(auth) do
:chinese -> "https://owner-api.vn.cloud.tesla.cn"
_global -> "https://owner-api.teslamotors.com"
end
TeslaApi.get(endpoint_url <> "/api/1/vehicles", opts: [access_token: auth.token])
|> handle_response(transform: &result/1)
end

@fsvm88
Copy link

fsvm88 commented Jan 23, 2024

I believe they switched over to the new fleet APIs for new logins.

Got this warning email from TeslaFi this morning ->

In the past few hours, Tesla has changed to a new officially supported Tesla API to connect your car to the TeslaFi.com service.

Please login to your TeslaFi.com account as soon as possible, if you have not already changed your connection, to reconnect TeslaFi.com with your car so logging will resume as soon as possible.

When you login, you will see a message in the top right of the site with instructions on how to make the change.  Please reference the image below as an example.  This process will only take a few moments. Feel free to go to help->open and open a support ticket if you happen to run into any issues.

While we know this is an inconvenience, it’s a wonderful change that Tesla is officially supporting 3rd party companies like TeslaFi.com and it will provide a stable foundation for us in the future!

Tessie did not warn me to switch immediately, so perhaps tokens obtained for the old API will work for a while, but going into Settings > Connectivity I could see "Upgrade to new APIs" or something like that, did it, and followed the same process. You login to your Tesla account, and grant privileges to the application that wants access, just like any oauth2 application.

@brianmay
Copy link
Collaborator

Yes, that is my concern. That above change in URL to list the vehicles will work - I was able to get a new token using tesla_auth, and then call the above URL. But I wonder for how long.

Not really willing to spend much time on changing APIs right now when when the the API could get pay-walled at any time without notice, and the charges are likely to be setup for big companies like Uber, and completely ignore the open source community,

@lotharbach
Copy link

TeslaFi have their argument backwards in my opinion. Tesla did not change "to" anything. Tesla disabled an API endpoint on the Owner API they have not been using themselves for probably a long time, which I think is fair game for them to do on an internal API. The community had another look and found the right request that Tesla is using themselves, so we can be back in business.

Of course this could be the start of a never-ending chain of changes the community would need to catch up on, now that "partner" Apps can be build on the Fleet API, but maybe wait for a few more that feel "hostile" before giving up?

@brianmay
Copy link
Collaborator

My concerns above about not passing the authorisation header may not be correct. I think the authorization header is added for all requests via the middleware library. This is configured here:

plug TeslaApi.Middleware.TokenAuth

Which in turn adds the header here:

token -> Tesla.put_header(env, "Authorization", "Bearer " <> token)

I also think that the ?orders=true is not required.

If so, this should fix the problem:

diff --git a/lib/tesla_api/vehicle.ex b/lib/tesla_api/vehicle.ex
index 1ff0690b..9c25743d 100644
--- a/lib/tesla_api/vehicle.ex
+++ b/lib/tesla_api/vehicle.ex
@@ -29,7 +29,7 @@ defmodule TeslaApi.Vehicle do
         _global -> "https://owner-api.teslamotors.com"
       end

-    TeslaApi.get(endpoint_url <> "/api/1/vehicles", opts: [access_token: auth.token])
+    TeslaApi.get(endpoint_url <> "/api/1/products", opts: [access_token: auth.token])
     |> handle_response(transform: &result/1)
   end

@brianmay
Copy link
Collaborator

brianmay commented Jan 23, 2024

TeslaFi have their argument backwards in my opinion. Tesla did not change "to" anything. Tesla disabled an API endpoint on the Owner API they have not been using themselves for probably a long time, which I think is fair game for them to do on an internal API. The community had another look and found the right request that Tesla is using themselves, so we can be back in business.

I think it clearly shows that Tesla have no respect for the open source community, or they would have produced an official API that we could use long ago. And the Fleet API is not open source friendly, it is not possible for open source software to distribute client_id and client_secret values the way proprietary web services can. Instead every user would have to become a developer and request these values.

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Jan 23, 2024

@brianmay do you open a PR? We can then test with out ghcr image.
I'm not sure if only changing

TeslaApi.get(endpoint_url <> "/api/1/vehicles", opts: [access_token: auth.token])
will solve the issue

@brianmay
Copy link
Collaborator

brianmay commented Jan 23, 2024

I can't do any testing right now. Without risking my working TeslaMate setup. Will do a PR (unless somebody else beats me to it), but not right now.

Also worth noting: I am guessing that API will return more then just cars. So may need some filtering, we are only interested in cars. I only have cars though, so I can't test this.

@JakobLichterfeld
Copy link
Collaborator

Agree, I will open a PR to have a ghcr image which we can test on test machines

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Jan 23, 2024

Ready for testing on test machines, DO NOT use on Production nor stop your Production: https://github.com/teslamate-org/teslamate/pkgs/container/teslamate/169975917?tag=pr-3630
ghcr.io/teslamate-org/teslamate:pr-3630

@weljajoh
Copy link

weljajoh commented Jan 23, 2024

FYI: I could make my failing TeslaPy script working again by patching TeslaPy's vehicle_list() to use the PRODUCT_LIST API and adding a negative test for a non-existant vehicle resource_type which gets us the vehicle list data (should really be a test for not a battery or solar, bur oh well)

pi@teslamate:~/.local/lib/python3.9/site-packages/teslapy $ diff -u __init__.py.orig __init__.py
--- __init__.py.orig	2024-01-23 10:27:36.591958142 +0100
+++ __init__.py	2024-01-23 10:28:11.571293210 +0100
@@ -372,7 +372,8 @@
 
     def vehicle_list(self):
         """ Returns a list of `Vehicle` objects """
-        return [Vehicle(v, self) for v in self.api('VEHICLE_LIST')['response']]
+        return [Vehicle(v, self) for v in self.api('PRODUCT_LIST')['response']
+                if v.get('resource_type') != 'vehicle']
 
     def battery_list(self):
         """ Returns a list of `Battery` objects """

So teslamate's get vehicle_list could be altered similarly I think.

@olexs
Copy link
Contributor

olexs commented Jan 23, 2024

Can confirm the test image from the PR #3630 works for me. Ran on an old machine of mine with a clean setup, latest image produces the "fleet API" error:

teslamate_1  | 2024-01-23 10:26:55.794 [info] Migrations already up
teslamate_1  | 2024-01-23 10:27:05.316 [info] System Info: Erlang/OTP 26 (jit)
teslamate_1  | 2024-01-23 10:27:05.316 [info] Version: 1.28.2
teslamate_1  | 2024-01-23 10:27:05.472 [info] Running TeslaMateWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
teslamate_1  | 2024-01-23 10:27:05.478 [info] Access TeslaMateWeb.Endpoint at http://******
teslamate_1  | 2024-01-23 10:27:08.989 [info] tzdata release in place is from a file last modified Fri, 22 Oct 2021 02:20:47 GMT. Release file on server was last modified Fri, 22 Dec 2023 09:25:37 GMT.
teslamate_1  | 2024-01-23 10:27:12.996 [info] Tzdata has updated the release from 2021e to 2023d
teslamate_1  | 2024-01-23 10:27:19.361 [info] GET /
teslamate_1  | 2024-01-23 10:27:19.384 [info] Sent 302 in 22ms
teslamate_1  | 2024-01-23 10:27:19.485 [info] GET /sign_in
teslamate_1  | 2024-01-23 10:27:19.504 [info] Sent 200 in 19ms
teslamate_1  | 2024-01-23 10:29:32.631 [info] POST https://auth.tesla.com/oauth2/v3/token -> 200 (368.355 ms)
teslamate_1  | 2024-01-23 10:29:32.656 [info] Scheduling token refresh in 6 h
teslamate_1  | 2024-01-23 10:29:32.804 [info] GET https://owner-api.teslamotors.com/api/1/vehicles -> 412 (158.923 ms)
teslamate_1  | 2024-01-23 10:29:32.805 [warning] TeslaApi.Error / %{"error" => "Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info", "error_description" => "", "response" => nil}
teslamate_1  | 2024-01-23 10:29:32.805 [warning] Could not get vehicles: :unknown

pr-3630 starts up successfully:

teslamate_1  | 2024-01-23 10:30:56.964 [info] Migrations already up
teslamate_1  | 2024-01-23 10:31:06.780 [info] System Info: Erlang/OTP 26 (jit)
teslamate_1  | 2024-01-23 10:31:06.780 [info] Version: 1.28.2
teslamate_1  | 2024-01-23 10:31:07.302 [info] POST https://auth.tesla.com/oauth2/v3/token -> 200 (384.315 ms)
teslamate_1  | 2024-01-23 10:31:07.302 [info] Refreshed api tokens
teslamate_1  | 2024-01-23 10:31:07.338 [info] Scheduling token refresh in 6 h
teslamate_1  | 2024-01-23 10:31:07.402 [info] Running TeslaMateWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
teslamate_1  | 2024-01-23 10:31:07.413 [info] Access TeslaMateWeb.Endpoint at http://******
teslamate_1  | 2024-01-23 10:31:07.698 [info] Starting logger for '******'
teslamate_1  | 2024-01-23 10:31:07.814 car_id=1 [info] Start / :asleep
teslamate_1  | 2024-01-23 10:31:10.459 [info] tzdata release in place is from a file last modified Fri, 22 Oct 2021 02:20:47 GMT. Release file on server was last modified Fri, 22 Dec 2023 09:25:37 GMT.
teslamate_1  | 2024-01-23 10:31:14.692 [info] Tzdata has updated the release from 2021e to 2023d
teslamate_1  | 2024-01-23 10:31:28.434 [info] GET /
teslamate_1  | 2024-01-23 10:31:28.448 [info] Sent 200 in 14ms

@martinblq
Copy link

Thank you for your help. I'm not sure to understand if I still can use Owners API keys or if I have to use Fleet API. Owners API seems don't work.

To test our current workaround, you do not need to change anything else. If your current setup is working, do not change nor restart.

ok so it doesn't work for me :(
Capture d’écran 2024-01-25 à 12 40 50

2024-01-25 12:43:52 teslamate-1  | 2024-01-25 11:43:52.677 [info] Migrations already up
2024-01-25 12:43:53 teslamate-1  | 2024-01-25 11:43:53.758 [info] System Info: Erlang/OTP 26 (jit)
2024-01-25 12:43:53 teslamate-1  | 2024-01-25 11:43:53.758 [info] Version: 1.28.2
2024-01-25 12:43:54 teslamate-1  | 2024-01-25 11:43:54.489 [info] POST https://auth.tesla.com/oauth2/v3/token -> 200 (712.822 ms)
2024-01-25 12:43:54 teslamate-1  | 2024-01-25 11:43:54.490 [info] Refreshed api tokens
2024-01-25 12:43:54 teslamate-1  | 2024-01-25 11:43:54.501 [info] Scheduling token refresh in 6 h
2024-01-25 12:43:54 teslamate-1  | 2024-01-25 11:43:54.505 [info] Running TeslaMateWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
2024-01-25 12:43:54 teslamate-1  | 2024-01-25 11:43:54.506 [info] Access TeslaMateWeb.Endpoint at http://localhost
2024-01-25 12:43:55 teslamate-1  | 2024-01-25 11:43:55.028 [info] Starting logger for ''
2024-01-25 12:43:55 teslamate-1  | 2024-01-25 11:43:55.038 [notice] Application teslamate exited: TeslaMate.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeslaMate.Vehicles
2024-01-25 12:43:55 teslamate-1  |     ** (EXIT) an exception was raised:
2024-01-25 12:43:55 teslamate-1  |         ** (Ecto.Query.CastError) deps/ecto/lib/ecto/repo/queryable.ex:461: value `"STE20231018-00662"` in `where` cannot be cast to type :integer in query:
2024-01-25 12:43:55 teslamate-1  | 
2024-01-25 12:43:55 teslamate-1  | from c0 in TeslaMate.Log.Car,
2024-01-25 12:43:55 teslamate-1  |   where: c0.eid == ^"STE20231018-00662",
2024-01-25 12:43:55 teslamate-1  |   select: c0
2024-01-25 12:43:55 teslamate-1  | 
2024-01-25 12:43:55 teslamate-1  |             (elixir 1.16.0) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
2024-01-25 12:43:55 teslamate-1  |             (elixir 1.16.0) lib/enum.ex:1826: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
2024-01-25 12:43:56 teslamate-1  | Kernel pid terminated (application_controller) ("{application_start_failure,teslamate,{{shutdown,{failed_to_start_child,'Elixir.TeslaMate.Vehicles',{#{message => <<\"deps/ecto/lib/ecto/repo/queryable.ex:461: value `\\"STE20231018-00662\\"` in `where` cannot be cast to type :integer in query:\n\nfrom c0 in TeslaMate.Log.Car,\n  where: c0.eid == ^\\"STE20231018-00662\\",\n  select: c0\n\">>,type => integer,value => <<\"STE20231018-00662\">>,'__struct__' => 'Elixir.Ecto.Query.CastError','__exception__' => true},[{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,2528}]},{'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,1826}]}]}}},{'Elixir.TeslaMate.Application',start,[normal,[]]}}}")
2024-01-25 12:43:56 teslamate-1  | 
2024-01-25 12:43:56 teslamate-1  | Crash dump is being written to: erl_crash.dump...done

@lotharbach
Copy link

@martinblq thanks for testing! I bet you have a tesla energy product.

This clearly shows how an additional check is required to get vehicles only and my proposal is to use "vehicle_id" (#3630 (comment)) - but my elixir coding is not good enough to just go ahead and propose the exact code change.

The code is currently trying to parse id as an integer, which then fails for energy products.

This is the fleet api example response, but I'd bet owner API just looks the same:


[
 {
  "id": 100021,
  "user_id": 429511308124,
  "vehicle_id": 99999,
  "vin": "5YJ3000000NEXUS01",
  "color": null,
  "access_type": "OWNER",
  "display_name": "Owned",
  "option_codes": "TEST0,COUS",
  "cached_data": null,
  "granular_access": {
   "hide_private": false
  },
  "tokens": [
   "4f993c5b9e2b937b",
   "7a3153b1bbb48a96"
  ],
  "state": null,
  "in_service": false,
  "id_s": "100021",
  "calendar_enabled": false,
  "api_version": null,
  "backseat_token": null,
  "backseat_token_updated_at": null,
  "command_signing": "off"
 },
 {
  "energy_site_id": 429124,
  "resource_type": "battery",
  "site_name": "My Home",
  "id": "STE12345678-12345",
  "gateway_id": "1112345-00-E--TG0123456789",
  "energy_left": 35425,
  "total_pack_energy": 39362,
  "percentage_charged": 90,
  "battery_power": 1000
 }
]

@martinblq
Copy link

@martinblq thanks for testing! I bet you have a tesla energy product.

This clearly shows how an additional check is required to get vehicles only and my proposal is to use "vehicle_id" (#3630 (comment)) - but my elixir coding is not good enough to just go ahead and propose the exact code change.

The code is currently trying to parse id as an integer, which then fails for energy products.

This is the fleet api example response, but I'd bet owner API just looks the same:


[
 {
  "id": 100021,
  "user_id": 429511308124,
  "vehicle_id": 99999,
  "vin": "5YJ3000000NEXUS01",
  "color": null,
  "access_type": "OWNER",
  "display_name": "Owned",
  "option_codes": "TEST0,COUS",
  "cached_data": null,
  "granular_access": {
   "hide_private": false
  },
  "tokens": [
   "4f993c5b9e2b937b",
   "7a3153b1bbb48a96"
  ],
  "state": null,
  "in_service": false,
  "id_s": "100021",
  "calendar_enabled": false,
  "api_version": null,
  "backseat_token": null,
  "backseat_token_updated_at": null,
  "command_signing": "off"
 },
 {
  "energy_site_id": 429124,
  "resource_type": "battery",
  "site_name": "My Home",
  "id": "STE12345678-12345",
  "gateway_id": "1112345-00-E--TG0123456789",
  "energy_left": 35425,
  "total_pack_energy": 39362,
  "percentage_charged": 90,
  "battery_power": 1000
 }
]

You are right, I have a Tesla Wall connector. :'(

@SoftEvleh
Copy link

I have a Wall Connector too and it doesn't work

@drmaettu
Copy link

Same here

@sbkbg
Copy link

sbkbg commented Jan 26, 2024

Same here :( Internal server error . I have a wall connector too.

@simonhaslam
Copy link

I only discovered Teslamate yesterday. I had the "Endpoint is only available on fleetapi" error, but have it running properly now using pr-3630 (one car, no other Tesla products).
Sounds like there might be bumpy times ahead on the API front, but thanks for all your hard work everyone!

@JakobLichterfeld
Copy link
Collaborator

Btw, there is a new test build, see: #3630 (comment)

@sbkbg
Copy link

sbkbg commented Jan 26, 2024

Btw, there is a new test build, see: #3630 (comment)

Hi. Is this a NEW updated build from today of this pr-3630 , because yesterday I've tryed this in my .yaml config "ghcr.io/teslamate-org/teslamate:pr-3630" and the results were the same error blank page ?

@brianmay
Copy link
Collaborator

@sbkbg Make sure you do a "docker pull ghcr.io/teslamate-org/teslamate:pr-3630" first because Docker won't automatically update the imagine if that tag is already downloaded.

@sbkbg
Copy link

sbkbg commented Jan 26, 2024

@sbkbg Make sure you do a "docker pull ghcr.io/teslamate-org/teslamate:pr-3630" first because Docker won't automatically update the imagine if that tag is already downloaded.

i've done :

docker compose down
docker images -a
docker rm (ID of the existing teslamate container)

and after that I've done the docker compose up -d (with the new edited line for the location container of teslamate - "pr-3630"

so I can be shure that the Teslamate container is pr-3630 :)

id pulled automaticaly the container and sayed that the ather parts are here and started .
after that I went to IP.........:4000 and it asked me to login , I've inputed the tockens and It sayed login successful BUT no map no car name and statistics and when I go to grafana in the dashboards there is only red excamationmarks :( that was yesterday . That's why I'm asking is there a new compile from today of the "pr-3630"

after that on my pi (because the first place is a cloud instance) - i've "pruned -a" :) all the images and all the volumes to be shure that is a clean install :) and started the yaml again but the result was the same blank after loging in :(

@brianmay
Copy link
Collaborator

brianmay commented Jan 26, 2024

I don't think any of those steps will get Docker to pull the latest image. Killing the container and restarting it have it use the existing pr-3630 image. Only if that doesn't exist will Docker try to look for it upstream.

You need to do something like docker pull ghcr.io/teslamate-org/teslamate:pr-3630.

@JakobLichterfeld
Copy link
Collaborator

Is this a NEW updated build from today of this pr-3630

Yes

@RickyTR
Copy link

RickyTR commented Jan 27, 2024

Btw, there is a new test build, see: #3630 (comment)

Will this solve the problem related to have a wall charger and a car?

@JakobLichterfeld
Copy link
Collaborator

Will this solve the problem related to have a wall charger and a car?

That's the plan, yes.

@KWReid
Copy link

KWReid commented Jan 27, 2024

408 errors are typically normal, just means that Tesla API was unable to talk to your car for some reason.

Yup. I'd seen 408's before on my side, but they were infrequent. This time I was only getting 408's so I'd pessimisticly assumed my call was being blocked somehow. :)

After trying the same code today, it's now working again with the https://owner-api.teslamotors.com/api/1/products?orders=true endpoint instead of just /vehicles. The details call still works without modification.

@RickyTR
Copy link

RickyTR commented Jan 29, 2024

Will this solve the problem related to have a wall charger and a car?

That's the plan, yes.

@JakobLichterfeld Do you think I can update my docker image to avoid an unexpected restart of the current image?

@JakobLichterfeld
Copy link
Collaborator

Do you think I can update my docker image to avoid an unexpected restart of the current image?

No need to so so imo

@idominiki
Copy link

Hi together!
Today's morning I noticed, that I'm logged out of teslamate. I need to sign in with token.

I just updated to the ghcr.io/teslamate-org/teslamate:pr-3630 image. How can I login again?

@jolcese
Copy link

jolcese commented Feb 1, 2024

Hi together! Today's morning I noticed, that I'm logged out of teslamate. I need to sign in with token.

I just updated to the ghcr.io/teslamate-org/teslamate:pr-3630 image. How can I login again?

https://docs.teslamate.org/docs/faq#how-to-generate-your-own-tokens ?

@shivaagarwal1
Copy link

Is there any way I can use this fix on Home Assistant Teslamate Add On?

https://github.com/matt-FFFFFF/hassio-addon-teslamate

@JakobLichterfeld
Copy link
Collaborator

closed by #3630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tesla api Related to the Tesla API note:help wanted Extra attention is needed note:needs investigation The issue must be investigated first
Projects
None yet
Development

No branches or pull requests