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.
Hello all,

I'm new to the Tesla API. I've implemented a monitoring tool for my tesla that watches it continuously and logs trips, charges and all kinds of other information I can retrieve.


To do so I was polling the DriveState for my Tesla. Having read through the forum here I saw that some people got blocked for spamming the service. So I was wondering whether the way I have set up my system would be considered spamming. I'm polling every 10 seconds.


Since yesterday I can't login anymore, but that might be a general issue as I saw that more people experienced this. So I was wondering whether my account would be blocked (I get a 500 - internal server error).


I only learned about the streaming service recently, so I will look into that too.

Thanks in advance for any advice on how to poll for the cars state so that I know when it starts driving/charging.

boris
 
I see lots of HTTP 503 error messages with "timeout in request to 172.20.241.22:7654". Only about 10% of my requests complete with HTTP 200 OK. The system seems to be getting gradually worse and worse as more owners come online.

Agreed. It's in a pretty sad state. I don't think it's just a problem with more owners (though I'm sure that's exacerbating the problem). It seems to have started going downhill with the cutover to the newer api.
 
Yeesh, I have not been paying attention to this thread :)

I'm headed out on a trip next weekend, so I'm planning on tracking the car on my tracker web app again. I've got a laundry list of things to do on the apiary docs: Update for oAuth and 6.0 · Issue #7 · timdorr/model-s-api · GitHub

Thanks for everyone's hard work on this stuff!

Oh and for any Rubyists out there, I haven't put it in the main repo yet, but here's an update TeslaApi class: tesla-streamer/tesla_api.rb at master · timdorr/tesla-streamer · GitHub
 
Last edited:
I've finished up my Ruby gem and it's at 1.0.0: tesla_api | RubyGems.org | your community gem host

It's got a full test suite for all endpoints. The streaming API is the only thing missing because it's threaded and that's harder to test.

I found some inactive endpoints for "trunk_open" that asks for a "which_trunk", that can be either "front" or "rear". Hopefully, they'll turn that on soon. I can see a use case:

- Watch the car for being awake and then for it's trunk/frunk open state.
- Whenever you're outside of a home geofence and the trunk/frunk opens, assume something was put into the car.
- When you park back at your house, it automatically opens the trunk/frunk for you.

Getting to the settings screen to open the car can be somewhat cumbersome, so that would be a neat script to build out.
 
I've finished up my Ruby gem and it's at 1.0.0: tesla_api | RubyGems.org | your community gem host

It's got a full test suite for all endpoints. The streaming API is the only thing missing because it's threaded and that's harder to test.

I found some inactive endpoints for "trunk_open" that asks for a "which_trunk", that can be either "front" or "rear". Hopefully, they'll turn that on soon. I can see a use case:

- Watch the car for being awake and then for it's trunk/frunk open state.
- Whenever you're outside of a home geofence and the trunk/frunk opens, assume something was put into the car.
- When you park back at your house, it automatically opens the trunk/frunk for you.

Getting to the settings screen to open the car can be somewhat cumbersome, so that would be a neat script to build out.

Better test for all edge cases for that one...
 
The 18 digit "id" field in the new API is a pain in the JSON. It's sent as a number, not a string, and Javascript integers are only significant to 15 digits. Took a while to figure out why my REST calls were not working. Unfortunately you can't just JSON.parse() the response to https://owner-api.teslamotors.com/api/1/vehicles and expect to use "id". The shorter "vehicle_id" is fine but only because its currently fewer than 15 digits long. Now I have to pick apart the response the old fashioned way with regular expressions.
 
The 18 digit "id" field in the new API is a pain in the JSON. It's sent as a number, not a string, and Javascript integers are only significant to 15 digits. Took a while to figure out why my REST calls were not working. Unfortunately you can't just JSON.parse() the response to https://owner-api.teslamotors.com/api/1/vehicles and expect to use "id". The shorter "vehicle_id" is fine but only because its currently fewer than 15 digits long. Now I have to pick apart the response the old fashioned way with regular expressions.

You can't use the built-in JSON parsing in node/v8. You can use this instead: sidorares/json-bigint · GitHub
 
No, I doesn't work at all here :(
Maybe your cookies file already have a valid credential and you don't need to get one ?

Can you try to rename your cookies file to save it and test again to see if you get the same error than me ?

My apps don't store cookies because they authenticate each time. I also tried using curl with a new cookie file and it is still working for me. Not everyone gets load balanced to the same servers though so it might be just me.
 
That's incredible !!!!
Can you post here the exact curl command you used ?

With the new owner API, it doesn't work too :

curl -H "Content-Type: application/json" -d '{ "grant_type" : "password", "client_id" : "", "client_secret" : "", "email" : "[email protected]", "password" : "xxx" }' https://owner-api.teslamotors.com/oauth/token

gives me the error 500 something goes wrong.

Same problem with Visible Tesla 0.28.

But with Android and official application, no problem. My login/password are good, I can't understand what happens :(
 
That's incredible !!!!
Can you post here the exact curl command you used ?

With the new owner API, it doesn't work too :

curl -H "Content-Type: application/json" -d '{ "grant_type" : "password", "client_id" : "", "client_secret" : "", "email" : "[email protected]", "password" : "xxx" }' https://owner-api.teslamotors.com/oauth/token

gives me the error 500 something goes wrong.

Same problem with Visible Tesla 0.28.

But with Android and official application, no problem. My login/password are good, I can't understand what happens :(

A few things to check. Since curl is a command line tool (i.e. runs in a shell like "bash") it can interpret special characters in your email or password. Make sure you don't have any backslash "\", single or double quotes or special characters that curl or the shell will interpret before sending to Tesla.

Next, do you have a valid "client_id" and "client_secret"? You will need these two parameters for the new API to work. These values have not been posted but if you read the thread there are some ideas on how to get these values yourself.

Lastly, if Visible Tesla is not working then it is quite possible that Tesla has begun checking and filtering client requests based on the user agent sniffing or some other identification information that would differentiate the real mobile apps from third party apps and curl commands.

Rather than continuing in an escalating hacking exercise to get this stuff to work, many of us prefer to wait for an official SDK or API and stay in the good graces of Tesla.

Exact command is just as you have written but with values filled in for "client_id", "client_secret", "email", and "password".
 
Last edited: