Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register
  • We just completed a significant update, but we still have some fixes and adjustments to make, so please bear with us for the time being. Cheers!

Model S REST API

L-P-G

Member
Feb 20, 2016
358
345
Orlando, FL
apacheguy already said it, the vehicles endpoint specifically states the state of the vehicle for you to use your own logic, for example if your command requires the vehicle to be awake you can use the wake up endpoint to wake it then send your command, otherwise let is sleep as there is nothing to do since it was last awake.

Tesla Model S JSON API · Apiary
 

insaneoctane

Active Member
Apr 6, 2016
3,369
5,183
Southern California
I'm struggling a bit with my approach here, and soliciting input from those who get what I am looking to do... .

At 10pm I wake up my car to see if it is plugged in. If so, done. Easy.

If not, I want to start querying every 60 seconds to know with a minute that it was plugged in (because I need to stop some other tasks once I actually plug it in). If I poll the car every minute to see if it is plugged in, will that prevent it from sleeping? On the other hand If I wait until the vehicle endpoint shows offline, I don't have confidence that it wasn't plugged in between my 10pm check and the time it took to go back to sleep... I do know that if the car is asleep AND not plugged in that I could monitor the vehicles endpoint every minute and it would HAVE to be woken in order to be plugged in.... I just don't know how to handle between checking at 10pm and the car going to sleep....
Suggestions?
 

insaneoctane

Active Member
Apr 6, 2016
3,369
5,183
Southern California
The keepalive timer is set to 10 minutes. So pulling data with a frequency of every 10 minutes or less will keep the car awake.
SO, if I wake the car at 10pm and it is not plugged in and then I check if the car is awake in 11 minutes, if it is asleep, I have no way of knowing if it got plugged in during the 11 minute wait.... But if I check the car itself within the 11 minutes I will keep it awake.....
 

Dazboj

Member
May 9, 2017
86
25
UK
Can't get the streaming api to work either on Model 3 (2018.21.9 75bdbc11)

Looking through the APK, I found a "new" streaming endpoint:
Code:
StreamingServerEndpoints={LOCATION_STREAMING:"streaming/",AUTOPARK_SUMMON:"connect/"}

but I am unable to connect, server seems to not be able to connect to the car.

Code:
{"msg_type":"data:error","tag":"${vehicle_id}","value":"disconnected","error_type":"vehicle_disconnected"}

If anyone wants to try the new endpoint on their Model S or X I can send some sample code over

I can confirm another Model 3 that returns the same result and also a Model S that doesn't work with the old streaming endpoint is also receiving the vehicle_disconnected message!

Surely these would still have the location working in the Android app which uses this data stream, so there must be something we are missing.
 
  • Helpful
Reactions: apacheguy

brianman

Burrito Founder
Nov 10, 2011
17,515
2,980
Has anybody explored the APIs for checking referral information (available in the official mobile app)?
 
  • Like
Reactions: SG57

apacheguy

S Sig #255
Oct 21, 2012
5,071
1,238
So Cal
I can confirm another Model 3 that returns the same result and also a Model S that doesn't work with the old streaming endpoint is also receiving the vehicle_disconnected message!

Surely these would still have the location working in the Android app which uses this data stream, so there must be something we are missing.

It can still get location and speed from the vehicle state endpoint. This is what the iPhone app seems to do with mine since it only updates once every 5 s.
 

SG57

Former Vendor
Jul 24, 2016
400
570
Spokane, WA
Doh, turns out the new Speed Limit mode's property, current_limit_mph, and the Set Limit's property, limit_mph, are both actually double data types.

Makes sense though, those using the metric system would have an imprecise limit if rounding off to integer MPH.
 
Last edited:

dpskipper

Developer
Aug 4, 2016
187
44
Australia
I'm unable to play with any of the speed limit stuff for some reason.

Works using the mobile app, but directly hitting the API myself following @SG57 's guide, i keep getting this response from the server:
Code:
{"response":{"reason":"invalid_limit","result":false}}

Can anyone shed some light?

ps this is my request body:
Code:
{"limit_mph":80}

as far as i can tell, my API request is upto spec.

EDIT:

Ok this is really getting weird. I set the PIN via the app, but didn't clear it. Tried to activate speed limit mode via the API myself, and it said incorrect pin. I'm 100% sure the PIN is right. No matter what I input it doesn't want to work.
 
Last edited:

SG57

Former Vendor
Jul 24, 2016
400
570
Spokane, WA
@dpskipper , limit_mph must be a double. Try the following:
Code:
{"limit_mph":80.0}
To your second issue, Speed limit mode is different than how valet mode does it. You must supply a new pin or the correct pin when enabling the mode, disabling the mode, or clearing the pin.

The only command that doesn't require a pin is the speed limit set limit command, however this command requires speed limit mode to be disabled.
 

dpskipper

Developer
Aug 4, 2016
187
44
Australia
@dpskipper , limit_mph must be a double. Try the following:
Code:
{"limit_mph":80.0}
To your second issue, Speed limit mode is different than how valet mode does it. You must supply a new pin or the correct pin when enabling the mode, disabling the mode, or clearing the pin.

The only command that doesn't require a pin is the speed limit set limit command, however this command requires speed limit mode to be disabled.
Still getting invalid limit.

Even when I set the pin myself using the mobile app, when I try to revoke it using my script, it still says invalid PIN.

Very strange indeed.

EDIT:

I've verified that speed limit mode works via the Android App. Using a script, dosent matter what I send: activate, deactivate set limit, or clear pin they all return an error. I'm scratching my head as to what the problem is.

I can't even activate the mode, it says PIN code not set. I'm supplying the PIN in the body.
When I set the PIN via the Android app and repeat, it says invalid PIN.

Very strange.
 
Last edited:

tcprst

New Member
Jul 25, 2018
1
0
Washington D.C. Metro Area
Yes I actually managed to figure this out myself in the end.
It works fine for me. Model S 2018.21.9

Can you provide a plaintext example of this subscribe request? I'm unable to get my new Model S on version 2018.26 3bbd9fd to connect with the old stream API. I'm trying to use the new stream API and I'm sending a request like:
Code:
{'msg_type': 'data:subscribe', 'tag': '<vehicle ID>', 'token': '<base64 encoded email:token>', 'value': 'speed,odometer,soc,elevation,est_heading,est_lat,est_lng,est_corrected_lat,est_corrected_lng,native_latitude,native_longitude,native_heading,native_type,native_location_supported,power,shift_state'}

When I try to send that with wsta I get:
Code:
Disconnected!
VERB 1: Error: NoDataAvailable
 

Dazboj

Member
May 9, 2017
86
25
UK
Can you provide a plaintext example of this subscribe request? I'm unable to get my new Model S on version 2018.26 3bbd9fd to connect with the old stream API. I'm trying to use the new stream API and I'm sending a request like:
Code:
{'msg_type': 'data:subscribe', 'tag': '<vehicle ID>', 'token': '<base64 encoded email:token>', 'value': 'speed,odometer,soc,elevation,est_heading,est_lat,est_lng,est_corrected_lat,est_corrected_lng,native_latitude,native_longitude,native_heading,native_type,native_location_supported,power,shift_state'}

When I try to send that with wsta I get:
Code:
Disconnected!
VERB 1: Error: NoDataAvailable

Your request looks fine, the same as what I am sending.
New cars seem to return the Disconnected error, i've had this confirmed by a few owners of newer Model S, X and 3, however my 2017 Model S connects and works fine.
 

brianman

Burrito Founder
Nov 10, 2011
17,515
2,980
What's the current status on the REST API for Model 3? Have folks gotten it working yet? If not, how far are we?
 

brianman

Burrito Founder
Nov 10, 2011
17,515
2,980
What are you looking for? It's almost the same as Model S and X. It just works :)
Ok cool. I thought I heard a bit back that the API was just not working at all for 3 -- like, server-side. Maybe I misunderstood and/or it was resolved a bit back.
 

About Us

Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.

Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


SUPPORT TMC
Top