Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Model S REST API

This site may earn commission on affiliate links.
Yes! Yes! Yes! Works...I'm about to use that to get access tokens :) Thanks for posting that!

This Python code on Github by tdorssers works great. Including Captcha and multifactor authentication. Even includes a GUI.
I've also been looking at tdorssers implementation ... although I'll freely admit it's over my head to fully understand! Two questions:

He makes reference in his documentation to a get_vehicle_summary() call as this will not wake up the vehicle and can be used to determine if online, asleep, etc. I've not found this documented in the Tesla JSON API unofficial documentation page. Anyone have more details on how this is supposed to behave? I played with this in my own python code and have gotten it to work, but not sure I'm fully understanding how I best use it.

Regarding the refresh token process, anyone have any understand of at what point the refresh process 'expires' and you must go back through the full login/authentication? I know if I do something like reset my password to my account I'll need to redo the full login. I've refreshed my access token now twice, so my original login is going on about over 100 days ago. Just wondering if there is some point where I should proactively think about shutting my logger down and forcing it to go back through the full login process versus continue to use my saved token and refresh token.

Thanks.
 
I've also been looking at tdorssers implementation ... although I'll freely admit it's over my head to fully understand! Two questions:

He makes reference in his documentation to a get_vehicle_summary() call as this will not wake up the vehicle and can be used to determine if online, asleep, etc. I've not found this documented in the Tesla JSON API unofficial documentation page. Anyone have more details on how this is supposed to behave? I played with this in my own python code and have gotten it to work, but not sure I'm fully understanding how I best use it.

Regarding the refresh token process, anyone have any understand of at what point the refresh process 'expires' and you must go back through the full login/authentication? I know if I do something like reset my password to my account I'll need to redo the full login. I've refreshed my access token now twice, so my original login is going on about over 100 days ago. Just wondering if there is some point where I should proactively think about shutting my logger down and forcing it to go back through the full login process versus continue to use my saved token and refresh token.

Thanks.
I meant to post that I was able (not about) to get tokens now.

On your questions, it seems like get_vehicle_summary is accessing the vehicles endpoint on Tesla's API:

In __init__.py:
Code:
    def get_vehicle_summary(self):
        """ Determine the state of the vehicle's various sub-systems """
        self.update(self.api('VEHICLE_SUMMARY')['response'])
        return self

In endpoints.json:
Code:
"VEHICLE_SUMMARY": {
    "TYPE": "GET",
    "URI": "api/1/vehicles/{vehicle_id}",
    "AUTH": true
  }

And as far as I know, that endpoint doesn't reach out to the vehicle for information - I believe it's pulled from Tesla's own database.

Not sure about your second question.
 
I meant to post that I was able (not about) to get tokens now.

On your questions, it seems like get_vehicle_summary is accessing the vehicles endpoint on Tesla's API:

In __init__.py:
Code:
    def get_vehicle_summary(self):
        """ Determine the state of the vehicle's various sub-systems """
        self.update(self.api('VEHICLE_SUMMARY')['response'])
        return self

In endpoints.json:
Code:
"VEHICLE_SUMMARY": {
    "TYPE": "GET",
    "URI": "api/1/vehicles/{vehicle_id}",
    "AUTH": true
  }

And as far as I know, that endpoint doesn't reach out to the vehicle for information - I believe it's pulled from Tesla's own database.

Not sure about your second question.

@luckyj - Thanks for the reply.

The comment on the tdorssers github post for his python implementation says his get_vehicle_summary call 'gets the state of the vehicle (online, asleep, offline)'.

That's where I was interested in how I might incorporate this into my logger to better recognize when the vehicle is asleep such that I'd elect not to poll it to do a better job letting the car sleep to minimize vampire drain. That's where I was wondering if anyone has used this an could provide a little more detail on the nature of the response, whether this is a single state value or multiple values for online vs offline, awake versus asleep, etc.

I was able to work out the basic get request format as simply: /api/1/vehicles/{id}

The response is:
{​
'id': 1234567890123456,​
'vehicle_id': 123456789,​
'vin': '5YJSA1E26GFnnnnn',​
'display_name': 'VehicleName',​
'option_codes':'AD15,MDL3,PBSB,RENA,BT37,ID3W,RF3G,S3PB,DRLH,DV2W,W39B,APF0,COUS,BC3B,CH07,PC30,FC3P,FG31,GLFR,​
HL31,HM31,IL31,LTPB,MR31,FM3B,RS3H,SA3P,STCP,SC04,SU3C,T3CA,TW00,TM00,UT3P,WR00,AU3P,APH3,AF00,ZCST,​
MI00,CDM0',​
'color': None,​
'access_type': 'OWNER',​
'tokens': ['0123456789abcdef', 'abcdef9876543210'],​
'state': 'online',​
'in_service': False,​
'id_s': '12345678901234567',​
'calendar_enabled': True,​
'api_version': 14,​
'backseat_token': None,​
'backseat_token_updated_at': None​
}​

It appears what he is referring to as providing the (online, asleep, offline) looks like it must be just the 'state' value shown in the response above. The little I've tested it I've not observed anything other than 'state': 'online' in the response, but I may shut my logger down for a couple hours this weekend and then poll my car with this to see if I can capture a 'sleep' reply.
 
Last edited:
Hi Guys,

Hé, I can't manage to get a token with my local setup, I've always getting a "Bad Request" answer...
Could you please orient me to something working ? I'm newbie in Tesla Auth (not in IT tough :) ) and I'd like to make sure I'm using the right authentication mechanism.
Goal is to use Openhab, but even this platform is replying a "Bad request" when I try to get a token...
Thanks for your help.
 
Hi Guys,

Hé, I can't manage to get a token with my local setup, I've always getting a "Bad Request" answer...
Could you please orient me to something working ? I'm newbie in Tesla Auth (not in IT tough :) ) and I'd like to make sure I'm using the right authentication mechanism.
Goal is to use Openhab, but even this platform is replying a "Bad request" when I try to get a token...
Thanks for your help.
Tesla-info.com will generate the tokens for you which you can then paste into your flow.
Refresh functions correctly (for me I currently require a VPN endpoint in the USA for refresh)
 
Hi Guys,

Hé, I can't manage to get a token with my local setup, I've always getting a "Bad Request" answer...
Could you please orient me to something working ? I'm newbie in Tesla Auth (not in IT tough :) ) and I'd like to make sure I'm using the right authentication mechanism.
Goal is to use Openhab, but even this platform is replying a "Bad request" when I try to get a token...
Thanks for your help.
The code source that used for my setup written in python is based off the code taken from here:


I do not use MFA so cannot speak to any of that process. I do know if you try too many times in succession without success it will lock you out, so as you go through the debugging process you may need after a few trials to walk away from it for an hour or so before you try again.

Another one you could look at, also python based is:

This one appears to be more complete for the login authentication, including MFA and captcha.

Maybe combination of those might help you.
 
I thought this was mimicing the smartphone app isn't it ?
I mean, why the hell could I not reach the API ?

Side note : I'm living in Belgium, and in my Tesla is a leased one. For your information, Tesla.com doesn't show me my car, apparently a deal with the leasers here in Belgium...

That's wy the "mimicing" of the smart app is important to me as I've access to it.
 
I thought this was mimicing the smartphone app isn't it ?
I mean, why the hell could I not reach the API ?

Side note : I'm living in Belgium, and in my Tesla is a leased one. For your information, Tesla.com doesn't show me my car, apparently a deal with the leasers here in Belgium...

That's wy the "mimicing" of the smart app is important to me as I've access

Yes, it's the app API. Can you share a curl command, which demonstrates the problem?