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

brogge

New Member
Dec 9, 2014
2
0
Belgium
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
 

hans

P631
Sep 27, 2012
1,132
13
Menlo Park
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.
 

jpasqua

P19325
Feb 19, 2013
696
4
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.
 

hans

P631
Sep 27, 2012
1,132
13
Menlo Park
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.
Perhaps the new calendar integration added a lot more traffic on their systems and now everything else is suffering.
 

timdorr

Model S P90D w/AP2.0
Aug 2, 2012
468
75
Atlanta, Georgia, United States
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:

timdorr

Model S P90D w/AP2.0
Aug 2, 2012
468
75
Atlanta, Georgia, United States
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.
 

aviators99

Model S - R140
Jan 1, 2010
1,463
10
Weston, Florida, United States
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...
 

nlc

Member
Jul 1, 2013
657
25
Nantes, France

hans

P631
Sep 27, 2012
1,132
13
Menlo Park
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.
 

timdorr

Model S P90D w/AP2.0
Aug 2, 2012
468
75
Atlanta, Georgia, United States
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
 

nlc

Member
Jul 1, 2013
657
25
Nantes, France
The old login is still working for me. I do notice that a lot of the requests fail/timeout so you may just need to retry.

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 ?
 

hans

P631
Sep 27, 2012
1,132
13
Menlo Park
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.
 

nlc

Member
Jul 1, 2013
657
25
Nantes, France
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 :(
 

hans

P631
Sep 27, 2012
1,132
13
Menlo Park
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:

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