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.
What is surprising to me - if Tesla really changed the endpoint, wouldn't they have to update the Android / iOS app too to make it use this new endpoint? The official Tesla app on my Android phone has not been updated for weeks, but still Summon is working on it... I stand corrected: Summon via official Android app doesn't work for me anymore either... Getting "Unable to connect to the car" error message. All other functions in the app still work.
 
Last edited:
Tesla switched to WebSockets for Summon and HomeLink.

They connect to wss://streaming.vn.teslamotors.com/

On a successful connection, the server responds with
{"autopark":{"autopark_pause_timeout":2000,"autopark_stop_timeout":10000,"heartbeat_frequency":500},"connection_timeout":20000,"msg_type":"control:hello"}
followed by:
{"autopark_state":"ready","msg_type":"autopark:status"}
{"homelink_nearby":true,"msg_type":"homelink:status"}

During auto park/summon, the server will send a heartbeat, like this:
{"msg_type":"autopark:heartbeat_car","timestamp":488163277436.176025}
{"msg_type":"autopark:heartbeat_car","timestamp":488163277936.211975}

When summon forward is requested, the server replies with:
{"cmd_type":"autopark:cmd_forward","msg_type":"autopark:cmd_result","reason":"","result":true}.E{"msg_type":"autopark:heartbeat_car","timestamp":488163276934.765991}

When summon is cancelled, the server sends:
{"cmd_type":"autopark:cmd_abort","msg_type":"autopark:cmd_result","reason":"","result":true}
{"autopark_state":"aborting","msg_type":"autopark:status"}

{"latitude":43.589033,"longitude":-121.858813,"msg_type":"vehicle_data:location"} (altered to not publish my house's location :) )
{"autopark_state":"ready","msg_type":"autopark:status"}

Obviously, this is missing what the client sends to the server. That's mostly because it's either compressed or not ASCII and I need to recompile my test code to give me hex bytes instead of ASCII in that situation before I can figure out the commands.
 
Great sleuthing @Polyport! I am anxiously awaiting what you find on what to send from the client -> the server.

Tesla switched to WebSockets for Summon and HomeLink.

They connect to wss://streaming.vn.teslamotors.com/

On a successful connection, the server responds with
{"autopark":{"autopark_pause_timeout":2000,"autopark_stop_timeout":10000,"heartbeat_frequency":500},"connection_timeout":20000,"msg_type":"control:hello"}
followed by:
{"autopark_state":"ready","msg_type":"autopark:status"}
{"homelink_nearby":true,"msg_type":"homelink:status"}

During auto park/summon, the server will send a heartbeat, like this:
{"msg_type":"autopark:heartbeat_car","timestamp":488163277436.176025}
{"msg_type":"autopark:heartbeat_car","timestamp":488163277936.211975}

When summon forward is requested, the server replies with:
{"cmd_type":"autopark:cmd_forward","msg_type":"autopark:cmd_result","reason":"","result":true}.E{"msg_type":"autopark:heartbeat_car","timestamp":488163276934.765991}

When summon is cancelled, the server sends:
{"cmd_type":"autopark:cmd_abort","msg_type":"autopark:cmd_result","reason":"","result":true}
{"autopark_state":"aborting","msg_type":"autopark:status"}

{"latitude":43.589033,"longitude":-121.858813,"msg_type":"vehicle_data:location"} (altered to not publish my house's location :) )
{"autopark_state":"ready","msg_type":"autopark:status"}

Obviously, this is missing what the client sends to the server. That's mostly because it's either compressed or not ASCII and I need to recompile my test code to give me hex bytes instead of ASCII in that situation before I can figure out the commands.
 
  • Like
Reactions: Brett
@rog, it was not working for me either however, I rebooted my car computer and force shut down the app. When loading again it successfully connected and summon started working. My guess is Tesla kind of sends the connection data to the app and it updates the endpoints behind the seen! I couldn't decipher the client request either so hopefully @Polyport can figure it out :)
 
@Polyport You were close. They're using some interesting choices of JSON serialization for their message objects in the Android client. Not sure of the equivalent over on the iOS side, but I haven't looked into that version in a while. (Perhaps they're binding to Java now?)

Anyways, I'll list out some initial findings over on the Github repo: GitHub - timdorr/model-s-api: A Ruby gem and unofficial documentation of the Tesla JSON API

Damn. You beat me to it :) Just got finished decoding all the commands. All my stuff done is with iOS, what I'm seeing matches what you put on Github. I think you missed the autopark:heartbeat_app -> timestamp in your list
 
So since commands in PHP always return 404, I tried javascript:

Code:
<script>

var request = new XMLHttpRequest();

request.open('POST', 'https://owner-api.teslamotors.com/api/1/vehicles/<?=$VEHICLE_ID?>/wake_up');

request.setRequestHeader('Authorization', 'Bearer <?=$token?>');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
    alert ("response: "+this.status + " -- " + this.responseText);
  }
};

request.send();

</script>

And this is the result:

Code:
XMLHttpRequest cannot load https://owner-api.teslamotors.com/api/1/vehicles/71923157...0506/wake_up. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://iteconomy.ch' is therefore not allowed access. The response had HTTP status code 404.


Am I blocked or something??
 
So since commands in PHP always return 404, I tried javascript:
<snip>

Code:
XMLHttpRequest cannot load https://owner-api.teslamotors.com/api/1/vehicles/71923157...0506/wake_up. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://iteconomy.ch' is therefore not allowed access. The response had HTTP status code 404.


Am I blocked or something??

404 usually means that the vehicle id you're using is incorrect. What happens when you list vehicles? If that works, the proper vehicle id you should use is the "id" field from that response; not the "vehicle_id" field. Does querying for vehicle charge state work?


That javascript error you're getting is just because you can't do cross domain calls in a browser without the proper CORS headers.