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.
@stevelectric , for Android yes.

My app Dashboard for Tesla is the only one, as far as I know, that supports GCM push-notifications from Tesla. I'm in the process of adding these as triggers to my existing automatic behaviors feature, so things like "Honk Horn when charge interrupted" is a thing, or "Start HVAC when charge completes".

screenshot6.png


I reverse-engineered the official Tesla Motors Android app to get the GCM sender key (not posting), then to learn the APIs I had to disable certificate pinning in the app using a rooted Android device before sniffing the app traffic. You'll need to generate an InstanceID device token using the GCM sender key and this will register your device to receive GCM messages from Tesla, then register your device token with Tesla's servers using the POST APIs below to let Tesla's servers know they should be sending your device messages and for what account.

The following APIs are used to both configure which vehicles to subscribe to messages for, and what types of messages to receive. These requests all require the same Bearer token authentication header and the response bodies are straightforward enough so I won't detail those:
  • GET: api/1/notification_preferences
    QUERY: ?device_token={INSERT HERE}&device_type=android&platform=android&app_version=3.2.1-334&locale=en

  • POST: api/1/notification_preferences
    BODY:
    {
    "device_token":"{INSERT HERE}",
    "device_type":"android",
    "platform":"android",
    "app_version":"3.2.1-334",
    "locale":"en",
    "notification_preferences":{
    "alarm":true,
    "autopark_forward_started":true,
    "autopark_completed_success":true,
    "autopark_unavailable_plugged_in":true,
    "charging_started":true,
    "charging_interrupted":true,
    "charging_complete":true,
    "key_added":true,
    "key_removed":true,
    "update_available":true,
    "climate_keeper_ended_soc":true,
    "car_active":true,
    "refer_friend":true,
    "secret_level":true,
    "please_move_car":true,
    "grid_fault_contactor_trip":true,
    "grid_resync_success":true​
    }​
    }​

  • GET: api/1/vehicle_subscriptions
    QUERY: ?device_token={INSERT HERE}&device_type=android&bigint=false

  • POST: api/1/vehicle_subscriptions
    BODY:
    {
    "device_token":"{INSERT HERE}",
    "device_type":"android",
    "vehicle_subscriptions":[
    "1237331239112123"​
    ],
    "bigint":"false"​
    }​
Fortunately, or perhaps foolishly, Tesla is not restricting their push messages as package-specific. You can technically put the query parameters in the body for the GET requests above and it will work, but it's bad practice and shame on Tesla for supporting that. You will need to URL-encode your device token when used as a query parameter.

There are a number of known vehicle notifications that Tesla's notification_preferences API supports enabling/disabling the actual sending of the message to your device, such as charging started or car alarm. Then there are a number of vehicle notifications you cannot disable that will always be sent to your device once your device is registered with GCM and your device token is registered with Tesla, such as HomeLink or Summon (autopark) panic. How many of these there are or any details on these tyoes of messages are mostly unknown. Technically you could artificially disable these making them invisible to the user by not doing anything with them once you receive the push message, but I digress.

The actual data sent to you from Tesla in a push message can vary, but here is a sample of a charging started message:
Code:
google.sent_time=1510049591636,
delivery_confirmation=false,
vehicle_id=12307332123114123,
txid=123e7185bbc5d15f47a471123f6d124d,
view=CHARGE,
google.message_id=0:1231239591639270%d36240681cbfb536,
product_type=vehicle,
alert_id=ALERT_CHARGING_STARTED,
product_id=1237332679123123,
override_string=Charging started at 2:13 am with battery at 163 mi.,
collapse_key=ALERT_CHARGING_STARTED,
alert_args=["Cordette","2:13 am"],
alert_time=1510049591

Hopefully this gives you and everyone else a good overview.
 
Last edited:
Is there someone with firmware 2017.48 (AP2) that still gets usefull information from vehicle_state ? My car stopped reporting any trim details after installing .48. My other model S on 2017.28 (AP1) still reports all body color parts and other trim options.
 
@Prefect , newer firmwares have stopped reporting various, duplicated data from specific state endpoints. The data you're looking for likely now only exists in the vehicle_config state on newer firmwares.

@dpskipper , he means the push notifications you can enable in the official app to receive various notifications about your vehicle(s) automatically, like when your charge stops or starts, or summon/homelink actions.
 
  • Like
Reactions: Prefect
@Prefect , newer firmwares have stopped reporting various, duplicated data from specific state endpoints. The data you're looking for likely now only exists in the vehicle_config state on newer firmwares.

@dpskipper , he means the push notifications you can enable in the official app to receive various notifications about your vehicle(s) automatically, like when your charge stops or starts, or summon/homelink actions.
cheers mate. i didn't read his post properly the first time ;)
 
  • Like
Reactions: SG57
Not that I am aware. A pretty good portion of the unofficial API documentation floating around out there is from years ago thus deprecated and incomplete. It mostly serves as an introduction into signing in and getting a basic command sent since that has remained pretty much unchanged.

My understanding of the APIs comes thru trial and error, and reverse engineering the official app via sniffing its network traffic and decompiling. If I can find the time I could do a brain-dump and document what I know and use in my app as there are a lot of quirks and missing documentation I've discovered.
 
  • Like
Reactions: Prefect
@wayner , yes. In the charge state, there is a battery_heater_on proprety indicating whether the battery heater is on. I haven't discovered a command for turning the battery heater on or off, so far the only way I know of to turn the battery heater on is to charge the car.
 
I don't know if you had a chance to read the article but it said that this functionality is coming in a new update:
With the recently released 2017.50 vehicle software update and an upcoming mobile app update, Tesla owners will be able to independently activate a “battery preheating” feature through the mobile app – again if the car is plugged in.
 
Done some digging into the latest official app and APIs just now, found a lot of fun stuff - Model 3 bluetooth lock/unlock, open/close trunks command, and a lot more Powerwall integration (summary, detailed data, power history, energy history, backup reserve, site name, and operation mode).

There was a pretty major refactor in the official app (for Android anyway).

I don't see any new commands for starting or stopping the battery heater explicitly, perhaps that's coming soon.

The bluetooth lock/unlock is currently limited to Model 3s arbitrarily, I don't see anything in here preventing it's use on other models assuming they are running the right firmware and assuming the model 3 doesn't have any special hardware for it.

For Model 3 owners the service on the phone runs every 1 second once setup, seems a bit overkill. Newer Android versions prevent this kind of battery drain with its new background execution limits. Curious how the app will perform for Model 3 owners.

FWIW there is a ton of security around the bluetooth unlock and lock. It'll be hard to adequately test or replicate this kind of bluetooth unlock/lock, don't suppose anyone has a Model 3 lying around ;)
 
Last edited:
  • Like
Reactions: dpskipper
@SG57 Thanks! Any chance of posting the API calls?
I wonder if there is some special hardware security for the BT unlock that will only be in the Model 3s?
No offense but @SG57 has a product and spends a lot of time on this. I would think at some point he should be asked for all the details from his hard work and there likely would be 'competing' products that want this data for FREE. I'd be a little offended if I was him with your ongoing request. Not trying to be mean but I think there is a level of professional respect here that is missing. Peace out.
 
  • Like
Reactions: pilotSteve and SG57
No offense but @SG57 has a product and spends a lot of time on this. I would think at some point he should be asked for all the details from his hard work and there likely would be 'competing' products that want this data for FREE. I'd be a little offended if I was him with your ongoing request. Not trying to be mean but I think there is a level of professional respect here that is missing. Peace out.
I realize that he has a product - but I am not looking for any of his secrets or his IP, just the basic API calls. SG57, Allen Wong and others will have benefited from work done in the past to document the API, most especially to Tim Dorr. So providing that information is something that he can do to create goodwill, just like post 2141 where he provided some very useful information about notifications. It is not a big deal as someone will eventually release this info.

By the way, I am not a developer looking to monetize anything, I am a hobbyist who looks to do this sort of stuff for fun. I did play around with writing an Alexa skill a year ago and I may do some other work to interface the Tesla API to my Home Automation system. But I am not looking to steal anyone's ideas and make money from them.
 
By the way, I am not a developer looking to monetize anything, I am a hobbyist who looks to do this sort of stuff for fun. I did play around with writing an Alexa skill a year ago and I may do some other work to interface the Tesla API to my Home Automation system. But I am not looking to steal anyone's ideas and make money from them.
Thanks for your reply. I somewhat understood. Re: I'm not a developer comment -- Keep in mind that you pushing this publicly that you are not just getting the data yourself but for ANYONE else that could be competing with him so you are hurting him that way. No offense just food for thought on cause/effect.
 
  • Like
Reactions: Deslah and SG57
Thanks for your reply. I somewhat understood. Re: I'm not a developer comment -- Keep in mind that you pushing this publicly that you are not just getting the data yourself but for ANYONE else that could be competing with him so you are hurting him that way. No offense just food for thought on cause/effect.
Understood - but if that's the way Tim Dorr and other's felt then we would have much less today in terms of third party Tesla tools. And SG57 has been quite gracious in providing "proprietary" information in the past - as recently as 9 days ago as you can see further up on this thread.

I have not bought Dashboard as I live in the iOS world rather than Android, at least for now. But I have bought other similar third party tools, such as Remote S.
 
Understood - but if that's the way Tim Dorr and other's felt then we would have much less today in terms of third party Tesla tools. And SG57 has been quite gracious in providing "proprietary" information in the past - as recently as 9 days ago as you can see further up on this thread. I have not bought Dashboard as I live in the iOS world rather than Android, at least for now. But I have bought other similar third party tools, such as Remote S.
A very thoughtful reply, I understand and see your points. I apologize to all for taking the thread off course.

I love using this app (again replaced my deer wreck X recently) and appreciate the efforts by the author and others that have provided the tech API info. I just purchased the speed testing add-on the other day. What a cool feature even if you only use it a few times. I thought it was just a timer originally and didn't realize all the data it was able gathered for the testing.
 
@wayner and @scottf200 , I have no problem sharing technical details, but I do side on safety when it comes to sharing IDs, keys, and such.

There are a number of APIs not documented, both old and new, some I know how to use, some I don't. It would take me some time to document but here are 2 quick ones not documented elsewhere:

Revokes an authorization bearer access token or refresh token given by the /oauth/token endpoint. Requires the auth bearer token header. Revoking a refresh token will revoke all access tokens generated from that access token. You can generate an access token using a refresh token using the same /oauth/token endpoint but instead of email, password fields you use a refresh_token field and change the grant_type field from password to bearer.

POST:
/oauth/revoke
BODY:
{
"token":"{TOKEN HERE}"​
}

Actuates the front or rear trunk - you can open or close the rear trunk, but you can only open the front trunk. Currently only Model 3s support this, but there is no reason why other models can't. Requires the can_actuate_trunks property returned from the vehicle_config data endpoint to be true in order to work, likely to come in a firmware update for Model S and X's later.

POST:
/api/1/vehicles/{vehicle_id}/command/actuate_trunk
BODY:
{
"which_trunk":"rear" // or "front"​
}
 
Last edited:
  • Informative
Reactions: NicB72
I'm searching , but without going through all 108 pages of this thread does anyone know how the actual image is pulled back from Tesla so it represent my actual car as it does in the Tesla App?
g'day mate. Most likley either the app has a bunch of images stored in it with each possible color/wheel/sunroof/spoiler/nosecone combo.

The actual backend system that generates the images is called the tesla compositor...

All ya have to do is go to the tesla studio, play around with a config you like, and then open the image in a new tab... The URL that comes up has a bunch of parameters in it, those 'codes' are what tells the compositing system what the car looks like.

For a jump-start on how this system works, consult this thread: Tesla website compositor

cheers!
 
  • Helpful
Reactions: scottf200