TeslaPy icon indicating copy to clipboard operation
TeslaPy copied to clipboard

Seems like the teslapy is no longer working with the new Tesla APIs

Open aviadoffer opened this issue 1 year ago • 58 comments

I'm now getting an error : Endpoint is only available on fleetapi I understand that this is due to the new API requirements, just wondering if there is a plan to update Teslapy project? Thanks in advance!

aviadoffer avatar Jan 23 '24 02:01 aviadoffer

Perhaps the intent was to rely on Tesla to support these apps, sadly I made my code rather reliant on the easy calls in TeslaPy

israndy avatar Jan 23 '24 06:01 israndy

Same here on vehicle_list()

requests.exceptions.HTTPError: 412 Client Error: Endpoint is only available on fleetapi. Visit https://developer.tesla.com/docs for more info for url: https://owner-api.teslamotors.com/api/1/vehicles

doubledrat avatar Jan 23 '24 08:01 doubledrat

Yes access to the https://owner-api.teslamotors.com/api/1/vehicles endpoint stopped sometime over night (in UK), I would guess that for vehicle data you now have to use the Fleet API.

However api/1/products still works, so if you are using TeslaPy for powerwalls then removing refernce to tesla.vehicle_list() from your client scripts will keep working for now.

DaveTBlake avatar Jan 23 '24 09:01 DaveTBlake

Yes access to the https://owner-api.teslamotors.com/api/1/vehicles endpoint stopped sometime over night (in UK), I would guess that for vehicle data you now have to use the Fleet API.

However api/1/products still works, so if you are using TeslaPy for powerwalls then removing refernce to tesla.vehicle_list() from your client scripts will keep working for now.

yes, but for how long? :(

I looked at registering for the fleet api, but you have to be a business :(

doubledrat avatar Jan 23 '24 09:01 doubledrat

In the same boat as you guys. I just tried the Home Assistant Tesla HACS integration and that works fine for 2 cars so I'm guessing there other implementations available to get at our Tesla data. Also see issue 150

Chillywasher avatar Jan 23 '24 10:01 Chillywasher

This patch makes it work again for me by switching from VEHICLE_LIST to PRODUCT_LIST and filtering out batteries and solar (there is no 'vehicle' resource_type in the vehicle product response)

--- __init__.py.orig	2024-01-23 10:27:36.591958142 +0100
+++ __init__.py	2024-01-23 11:25:29.264901231 +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') != 'battery' and v.get('resource_type') != 'solar']
 
     def battery_list(self):
         """ Returns a list of `Battery` objects """

weljajoh avatar Jan 23 '24 10:01 weljajoh

I was able to register my app on tesla dev site ( Application Onboarding Request Approved ) . so now I have the keys from tesla. but how do I plug those into this API ?

aviadoffer avatar Jan 23 '24 15:01 aviadoffer

Same issue here. Looking at the doc there seems to be a way to make it work, for free, for a while, with limited no. of requests. https://developer.tesla.com/docs/fleet-api

dan-cristian avatar Jan 24 '24 10:01 dan-cristian

I tried to create a business account using valid business details but got the error at the end: Unable to Onboard, Contact your account manager....

dan-cristian avatar Jan 24 '24 11:01 dan-cristian

@dan-cristian uncheck the first option (get personal data etc) and it will work.

aviadoffer avatar Jan 24 '24 13:01 aviadoffer

For the record I used https://github.com/fabianhu/tesla_api and manage to get everything I need. this method worked for me after help from the author

aviadoffer avatar Jan 24 '24 13:01 aviadoffer

This patch makes it work again for me by switching from VEHICLE_LIST to PRODUCT_LIST and filtering out batteries and solar (there is no 'vehicle' resource_type in the vehicle product response)

--- __init__.py.orig	2024-01-23 10:27:36.591958142 +0100
+++ __init__.py	2024-01-23 11:25:29.264901231 +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') != 'battery' and v.get('resource_type') != 'solar']
 
     def battery_list(self):
         """ Returns a list of `Battery` objects """

This works as long as there are no other products than battery and solar. I have a Wall Connector and this crashes.

A better way is to check if product has vin and vehicle_id. Use the following code and it works:

def vehicle_list(self):
    """ Returns a list of `Vehicle` objects """  
    return [Vehicle(v, self) for v in self.api('PRODUCT_LIST')['response'] 
            if 'vin' in v and 'vehicle_id' in v]

DeLN0 avatar Jan 24 '24 14:01 DeLN0

I just tried to create a business account using valid UK business details (by tax id it wants a VAT number and not a UTR) but got the error at the end: Unable to Onboard, Contact your account manager.

The only scope I checked was Powerwall Information, the first option get personal data was unchecked. Suggestions?

DaveTBlake avatar Jan 24 '24 16:01 DaveTBlake

I just tried to create a business account using valid UK business details (by tax id it wants a VAT number and not a UTR) but got the error at the end: Unable to Onboard, Contact your account manager.

The only scope I checked was Powerwall Information, the first option get personal data was unchecked. Suggestions?

DaveTBlake you can use the old API, you just need to replace def vehicle_list(self) function in the __init__.py file from teslapy library with this function:

def vehicle_list(self):
    """ Returns a list of `Vehicle` objects """  
    return [Vehicle(v, self) for v in self.api('PRODUCT_LIST')['response'] 
            if 'vin' in v and 'vehicle_id' in v]

DeLN0 avatar Jan 24 '24 17:01 DeLN0

I just tried to create a business account using valid UK business details (by tax id it wants a VAT number and not a UTR) but got the error at the end: Unable to Onboard, Contact your account manager.

The only scope I checked was Powerwall Information, the first option get personal data was unchecked. Suggestions?

As a suggestion try to enter browser console and check what messages you have there.

DeLN0 avatar Jan 24 '24 17:01 DeLN0

@dan-cristian uncheck the first option (get personal data etc) and it will work.

I also have this problem. In my case, i can't uncheck the first option because i can't go back to the first step.

Any suggestions?

Screenshot 2024-01-24 at 19 57 31

DeLN0 avatar Jan 24 '24 18:01 DeLN0

@DeLN0 I know that for now the Owner API works for Powerwall settings, and I have modified TeslaPy to keep my script working. But the end of Owner API is coming so I'm looking to see if I can jump throught the hoops to move the FleetAPI

As a suggestion try to enter browser console and check what messages you have there.

Neat idea. Console shows Content Security Policy: The page's settings blocked the loading of a resource at eval ("script-src").

Not sure what to make of that. My guess is that my URLs are the problem, I own a domain but use free-parking and that doesn't have a certificate. I couldn't see how to get Localhost working either, which could be all I need. My next step is to look for some free storage I have point my domain at. All in a lot of effort just to get a script for one user working.

DaveTBlake avatar Jan 24 '24 18:01 DaveTBlake

@DaveTBlake

Not sure what to make of that. My guess is that my URLs are the problem, I own a domain but use free-parking and that doesn't have a certificate. I couldn't see how to get Localhost working either, which could be all I need. My next step is to look for some free storage I have point my domain at. All in a lot of effort just to get a script for one user working.

In my case, if i go to https://developer.tesla.com on my iPhone this is what i get, even though my domain is fine and certicates are up to date:

IMG_8792

DeLN0 avatar Jan 24 '24 18:01 DeLN0

I managed to get developer access working yesterday following this tutorial.

Edited to show author's blog instead of the medium.com version which is paywalled:

https://shankarkumarasamy.blog/2023/10/29/tesla-developer-api-guide-account-setup-app-creation-registration-and-third-party-authentication-configuration-part-1/

mshoe007 avatar Jan 25 '24 01:01 mshoe007

Paywalled

israndy avatar Jan 25 '24 01:01 israndy

@israndy that tutorial by Shanka Kumarasamy is also just in his blog too (not behind the Medium paywall) https://shankarkumarasamy.blog/2023/10/29/tesla-developer-api-guide-account-setup-app-creation-registration-and-third-party-authentication-configuration-part-1/

DaveTBlake avatar Jan 25 '24 08:01 DaveTBlake

I just tried to create a business account using valid UK business details (by tax id it wants a VAT number and not a UTR) but got the error at the end: Unable to Onboard, Contact your account manager. The only scope I checked was Powerwall Information, the first option get personal data was unchecked. Suggestions?

DaveTBlake you can use the old API, you just need to replace def vehicle_list(self) function in the __init__.py file from teslapy library with this function:

def vehicle_list(self):
    """ Returns a list of `Vehicle` objects """  
    return [Vehicle(v, self) for v in self.api('PRODUCT_LIST')['response'] 
            if 'vin' in v and 'vehicle_id' in v]

This would be good to to have in teslapy as a PR. This change worked for me, thanks!

the-mace avatar Jan 25 '24 17:01 the-mace

That patch allows TeslaPy to continue to do 'read' sorts of functions. But, if I try to issue a command, I get

 Client Error: Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api

I think the old commands API now only works for pre refresh (2021) S & X?

The rest of us have to use the Fleet API for sending commands to the car.

mshoe007 avatar Jan 25 '24 17:01 mshoe007

@mshoe007 I have a 2020 X and a 2022 X, both works fine with new API's to read data and to run commands. so moving to the fleet API works for me on both cars

aviadoffer avatar Jan 25 '24 19:01 aviadoffer

@aviadoffer I gave the https://github.com/fabianhu/tesla_api a try but got stuck at the step of building the go language part. Are there any extensions to be made to the readme to make it clearer? I'm running on a Raspberry Pi 3 btw

JanJaapKo avatar Jan 25 '24 19:01 JanJaapKo

@JanJaapKo so I only did the simple step of importing the tesla_api_2024.py for the purpose of auth. placing the keys in TeslaKeys

so in a high level it looks like this:

from tesla_api import tesla_api_2024, TeslaAPI teslaApi = TeslaAPI() vehicles = teslaApi.get_vehicles_list()

Then I added the function I needed to the tesla_api_2024, example:

  def tesla_start_charge(self, vin):
  
          conn = http.client.HTTPSConnection("fleet-api.prd.na.vn.cloud.tesla.com")
          payload = json.dumps({})
          headers = {
              'Content-Type': 'application/json',
              'Authorization': f'Bearer {self.access_token}'
          }
          conn.request("POST", f"/api/1/vehicles/{vin}/command/charge_start", payload, headers)
          res = conn.getresponse()
          data = res.read()

and

  def tesla_set_charge_amp(self, vin , amps):

        conn = http.client.HTTPSConnection("fleet-api.prd.na.vn.cloud.tesla.com")
        payload = json.dumps({
            "charging_amps": f"{amps}"
        })
        headers = {
            'Content-Type': 'application/json',
            'Authorization': f'Bearer {self.access_token}'
        }
        conn.request("POST", f"/api/1/vehicles/{vin}/command/set_charging_amps", payload, headers)
        res = conn.getresponse()
        data = res.read()

etc...

aviadoffer avatar Jan 25 '24 20:01 aviadoffer

That patch allows TeslaPy to continue to do 'read' sorts of functions. But, if I try to issue a command, I get

 Client Error: Tesla Vehicle Command Protocol required, please refer to the documentation here: https://developer.tesla.com/docs/fleet-api

I think the old commands API now only works for pre refresh (2021) S & X?

The rest of us have to use the Fleet API for sending commands to the car.

Is your car newer than november 2023?

Tesla says November 2023 Newly delivered vehicles* will only support the Tesla Vehicle Command protocol after this date More info here: https://developer.tesla.com/docs/fleet-api#2023-11-17-vehicle-commands-endpoint-deprecation-timeline-action-required

DeLN0 avatar Jan 25 '24 20:01 DeLN0

got stuck at the step of building the go language part. Are there any extensions to be made to the readme to make it clearer? I'm running on a Raspberry Pi 3 btw

The build instructions are here: https://github.com/teslamotors/vehicle-command

You need a 32-bit install of go for a Raspberry Pi 3. (I assume you're running a 32-bit OS on it). If you are running 64-bit linux, get the go1.21.6.linux-arm64.tar.gz file.

 cd /tmp ; wget https://go.dev/dl/go1.21.6.linux-armv6l.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.6.linux-armv6l.tar.gz
PATH="/usr/local/go/bin:$HOME/go/bin:$PATH"
cd
git clone https://github.com/teslamotors/vehicle-command
cd vehicle-command/
go get ./...
go build ./...
go install ./...
ls $HOME/go/bin
ble*               tesla-control*     tesla-keygen*
tesla-auth-token*  tesla-http-proxy*  unlock*
tesla-control --help
Usage: tesla-control [OPTION...] COMMAND [ARG...]

Run tesla-control help COMMAND for more information. Valid COMMANDs are listed below.

 * Commands sent to a vehicle over the internet require a VIN and a token.
 * Commands sent to a vehicle over BLE require a VIN.
 * Account-management commands require a token.

Available OPTIONs:
  -ble
        Force BLE connection even if OAuth environment variables are defined
<etc>

Note you need to permanently set your PATH to include $HOME/bin/go if you have not already

mshoe007 avatar Jan 25 '24 22:01 mshoe007

@aviadoffer I gave the https://github.com/fabianhu/tesla_api a try but got stuck at the step of building the go language part. Are there any extensions to be made to the readme to make it clearer? I'm running on a Raspberry Pi 3 btw

@JanJaapKo please open an issue in my repo, I'll help!

@mshoe007 You can also compile on (Linux) PC , without installing Go on the Pi.

cd vehicle-command/cmd/tesla-control/
env GOOS=linux GOARCH=arm GOARM=7 
go build .

This generates an elf file, which can be directly executed on the Pi3. I just checked the .bash_history on my Pi, I did not install Go. Updated the readme too...

fabianhu avatar Jan 26 '24 22:01 fabianhu

@DaveTBlake @DeLN0

Is your domain pointing to a CNAME record by any chance? I ran into the same issue, after pointing it directly to an A record it worked

leepfrog-ger avatar Jan 27 '24 12:01 leepfrog-ger