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.
I have been running a script for the last 2 years that logs my vehicle state every 30 minutes. As of today it stopped working. When I send my credentials the return cookie info is missing the user_credentials. I just did a software update last night triggered by visiting the service center. Don't know if it is related. Anyone else having problems connecting to the REST API today?
 
this works for me via curl

Code:
curl -H "Authorization: Bearer 21727948e7d...f2506a21727" \
     -H "Content-Type: application/json" \
     --data '{"percent" : "80"}' \
     -i [URL="https://owner-api.teslamotors.com/api/1/vehicles/5162278...61511234/command/set_charge_limit"]https://owner-api.teslamotors.com/api/1/vehicles/516227861511234/command/set_charge_limit[/URL]


RETURNS


Code:
{"response":{"reason":"","result":true}}

Then check charge state

[request charge state]


Code:
curl -H "Authorization: Bearer 21727948e7d...f2506a21727" \
     -H "Content-Type: application/json" \
     -i [URL="https://owner-api.teslamotors.com/api/1/vehicles/5162278...61511234/data_request/charge_state"]https://owner-api.teslamotors.com/api/1/vehicles/516227861511234/data_request/charge_state[/URL]


RETURNS

Code:
{"response:{"charging_state":"Disconnected","charge_limit_soc":80,"charge_limit_soc_std":90,"charge_limit_soc_min":50,"charge_limit_soc_max":100,"charge_to_max_range":false,"battery_heater_on":false,"not_enough_power_to_heat":false,"max_range_charge_counter":0,"fast_charger_present":false,"fast_charger_type":"\u003Cinvalid\u003E","battery_range":113.35,"est_battery_range":103.03,"ideal_battery_range":128.9,"battery_level":57,"usable_battery_level":57,"battery_current":-0.6,"charge_energy_added":7.24,"charge_miles_added_rated":25.0,"charge_miles_added_ideal":28.5,"charger_voltage":0,"charger_pilot_current":0,"charger_actual_current":0,"charger_power":0,"time_to_full_charge":0.0,"trip_charging":false,"charge_rate":0.0,"charge_port_door_open":false,"motorized_charge_port":false,"scheduled_charging_start_time":null,"scheduled_charging_pending":false,"user_charge_enable_request":null,"charge_enable_request":false,"eu_vehicle":false,"charger_phases":null}}

Make sure you use the right vehicle id. It's the value of {id} and not {vehicle_id}
 
I have been running a script for the last 2 years that logs my vehicle state every 30 minutes. As of today it stopped working. When I send my credentials the return cookie info is missing the user_credentials. I just did a software update last night triggered by visiting the service center. Don't know if it is related. Anyone else having problems connecting to the REST API today?

There's a new API that uses OAuth tokens. The cookie method has been depreciated.

OK that is a good call, I bet that is it. Let me try that now.

- - - Updated - - -

No, that didn't do it either. It set the charge value to 50% when I requested 70%

When that happens, it means that you're getting closer. It means that the type of value is wrong for "70". Either it should be a string or a integer. It should be the opposite type of what you just did (i.e. feed it JSON.stringify a string if you gave it an integer). You're just one step away from getting it right. I'd tell you the answer, but my code is written for iOS apps, not Windows 8 or Windows phone or whatever you're coding for.
 
I have been running a script for the last 2 years that logs my vehicle state every 30 minutes. As of today it stopped working. When I send my credentials the return cookie info is missing the user_credentials. I just did a software update last night triggered by visiting the service center. Don't know if it is related. Anyone else having problems connecting to the REST API today?

hmm same here.. since +/- a week unable to connect using 'old' API

20150607 10:29:30 >> Error: Cannot Login to the Tesla Remote API The remote server returned an error: (500) Internal Server Error.

Maybe I missed something, but has this API been shut down ?
 
There's a new API that uses OAuth tokens. The cookie method has been depreciated.


Hey there! This is my first post here.

Anybody know where I can find documentation? I had the old one working just to tell me there are no vehicles on my account yet. That should change in the next two weeks, and I wanted to have a script notify me the second it goes online.

How did that work for you guys? did you have to login from within the car or did Tesla tie it to your account at the factory?

If someone could walk me through the new authentication flow that would be great..
 
Hey there! This is my first post here.

Anybody know where I can find documentation? I had the old one working just to tell me there are no vehicles on my account yet. That should change in the next two weeks, and I wanted to have a script notify me the second it goes online.

How did that work for you guys? did you have to login from within the car or did Tesla tie it to your account at the factory?

If someone could walk me through the new authentication flow that would be great..

Sniff the packets sent by the Tesla android or iOS app. The answer lies in there. There's no publicly posted client_id and secret key. And you need both to be able to get an OAuth token to issue GET and POST to the server. If you had my Remote S app, you can bypass the need for the client_id and secret key and copy and email the OAuth token to yourself from the app. And then it'll be as simple as editing your script to send the OAuth token in the header instead of passing a cookie.
 
After having spent hours decompiling and going through class after class (not familiar with android so I didn't know where not to bother looking), sniffing packets on iOS with a Charles proxy Ssl certificate, I'm pulling my hair out. And then it turns out the solution is $10 on the App Store. Thanks lol.

- - - Updated - - -

My question still stands: Did you have to login from your car to connect it to your account or did the car come already tied to your account before delivery? Anybody know how long before delivery the car went "online" accessible from the API account?
 
My question still stands: Did you have to login from your car to connect it to your account or did the car come already tied to your account before delivery? Anybody know how long before delivery the car went "online" accessible from the API account?

No you do not login from the car. Tesla associates your car's VIN with your existing tesla login credentials. The car will come with remote access turned off so you will have to go to settings in the car and turn it on (I think its called "mobile access" or something similar in the settings in the car).
 
streaming.js?

Sniff the packets sent by the Tesla android or iOS app. The answer lies in there. There's no publicly posted client_id and secret key. And you need both to be able to get an OAuth token to issue GET and POST to the server. If you had my Remote S app, you can bypass the need for the client_id and secret key and copy and email the OAuth token to yourself from the app. And then it'll be as simple as editing your script to send the OAuth token in the header instead of passing a cookie.

I have the token, now trying to make it work with streaming. I have tried this command:
Code:
curl -u <myusername>:<thetoken> 'https://streaming.vn.teslamotors.com/stream/<myvehicleID>/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading'

which didn't work (it didn't return any response at all). Other commands like setting charge point did. Am I missing something with respect to streaming? Also, is there any way to make the new Oauth/Token based API work with the streaming.js solution at github? I have my scripts based on that solution and I'd like to just plug in this token somewhere in lieu of the old cookie based method I'd used before.

Thanks!
 
Also, is there any way to make the new Oauth/Token based API work with the streaming.js solution at github? I have my scripts based on that solution and I'd like to just plug in this token somewhere in lieu of the old cookie based method I'd used before.

Thanks!

streaming.js automatically gets the OAUTH token for you so you don't need anything more than your tesla login and password to make it work.
Same is true of teslacmd.js which is a command line tool that is also included in the teslams package on github. It's very simple to use 'teslacmd' inside shell scripts or any other scripting language that can call out to the shell on Linux, Mac OS X, or Windows.

-hans