Tesla Owner API and Car Data

  • If you haven't taken delivery yet or plan on ordering you can still get the 6 months of FREE Supercharging only until December 31st all Model 3s now qualify! Call or email your Tesla delivery advisor and give them our code
  • Please post everything related to v9 (2018.39.x) into the version 9 MEGATHREAD. Please do your part to keep this site organized for everyone by looking around or doing a search BEFORE posting. Thanks

  • Winter is here and the forum is starting to get flooded with cold weather threads and posts. Please heed the suggested threads and posts before you post something related to cold weather. This is a great place to start: https://model3ownersclub.com/threads/teslas-in-cold-weather.5271
  • It's OK to discuss software issues here but please report bugs to Tesla directly at servicehelpna@teslamotors.com if you want things fixed.

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#1
Has anyone created or know of a simple web interface that queries your car and displays the results? I.E. the phone app and 3rd party sites like TeslaFi do some API call to the car and does something with the returned values (stores in a database, displays the values, etc.). Is there a simple web interface that one could enter their credentials or token and get/view the returned values? I am sure this is a simple thing for any web programmer, just looking for a tool the rest of us can use.

TIA.
 

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#3
This is a good starting point: https://tesla-api.timdorr.com/

Many people have written various apps and web pages that work off of this base.
Thanks - that looks like a start to what I am looking for - I have heard the terms JSON and RESTful API, etc. but have no idea how to set up something that authenticates, calls the api, then displays the results... I am sure it would be trivial for someone to slap up a simple web page that takes care of all that - just thought someone might have done it already ;)
 

NOGA$4ME

Top-Contributor
Joined
Sep 30, 2016
Messages
607
Location
Durham, NC
Tesla Owner
Model 3
Country
Country
#5
I think the OP wants to make their own web page. They would be using the 3rd party LIBRARY, but it would be running on their own machine with their own code.
 

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#6
I think the OP wants to make their own web page. They would be using the 3rd party LIBRARY, but it would be running on their own machine with their own code.
My thought was a web page anyone could use, but I guess there would be security concerns... so that said, can someone walk me through how to make the web call on my own??
 

Bokonon

Self-identified Teslaholic
Moderator
M3OC Supporting Member
Joined
Apr 12, 2017
Messages
2,146
Location
Boston
Tesla Owner
Model 3
Country
Country
#7
My thought was a web page anyone could use, but I guess there would be security concerns...
The closest solution I can think of would be a simple web page, ideally with no external source files, that called the Tesla API directly from client-side Javascript to generate your token. The page's source code would be concise and readable, so that anyone knowledgeable could easily confirm that it didn't do anything with your credentials other than package them up and send them to Tesla.

so that said, can someone walk me through how to make the web call on my own??
Do you have a Mac? If so, open a Terminal window, modify the command below to use your Tesla account's email address and password, and run it:

Code:
curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "grant_type=password" -F "client_id=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384" -F "client_secret=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3" -F "email=xxxxxx@yyyy.zzz" -F "password=********" "https://owner-api.teslamotors.com/oauth/token"
If you have Windows, you can download Curl from here and run the above command from a command-prompt window. I can provide more detailed instructions if needed.

EDIT: I should note that the above command only generates a Tesla API access token, it does not actually return any information about your car. Once you have a token, you will need to make additional API calls (with your access token) to query your car's status. The Apiary documentation linked above can help you generate curl commands for these API calls.
 
Last edited:

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#8
That's getting me close! I downloaded curl, then executed the command substituting my acct email and pw. It seems that all it did was give me an access token?
{"access_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","token_type":"bearer","expires_in":3888000,"refresh_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXX","created_at":1539298492}

Is there a second command I need to enter to get the state values indicated in the api documentation linked above?
(I am on Win10)

Thanks so much for the info - it is greatly appreciated!
 

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#9
Just saw your edit; I will see if I can figure out how to make the state call using the token... wish me luck :)
 

Bokonon

Self-identified Teslaholic
Moderator
M3OC Supporting Member
Joined
Apr 12, 2017
Messages
2,146
Location
Boston
Tesla Owner
Model 3
Country
Country
#10
That's getting me close! I downloaded curl, then executed the command substituting my acct email and pw. It seems that all it did was give me an access token?
Perfect! That's exactly what you want!

Next up is to query your Tesla account to get your vehicle ID. You can do this by using the "vehicles" endpoint, like so:

Code:
curl --include --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles"
That should give you a JSON response with an array of vehicles under your account. For each vehicle, you can see its VIN, configuration codes, current state (asleep / online / etc), and a few other things. Note the value of the "id" property (not the "vehicle_id" property), because you will use it with the following commands.

If you want to get more specific information about your vehicle, you'll need to wake it up if it's currently asleep. You can do this by opening the Tesla app, or you can issue a "wake" command through the API. (Note: replace {vehicle_id} with the value of the "id" property from the previous command.)

Code:
curl --include --request POST --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles/{vehicle_id}/wake_up"
The response to this command may indicate that your vehicle is still asleep, but if you're within earshot of your driveway/garage, you may hear your car make the usual clunking sounds that signal that it's waking up. After a short wait, your car should be awake (and you can confirm this by issuing the same "wake" command and checking the car's status).

Okay, so now your car's awake, how can you find out everything there is to know about its current state? Well, there's a handy endpoint for that:

Code:
curl --include --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles/{vehicle_id}/data"
That will basically give you everything the API knows about the car's current state and configuration. Copy and paste the JSON response into your favorite JSON formatting tool (example) to make it legible, and enjoy!

(Side note: looks like some new fields specific to firmware V9 capabilities have been added recently. Cool!)

For other API endpoints and further reading, Tim Dorr has a more complete, updated version of the API documentation here. The old Apiary site is still useful for quickly generating curl command with the correct syntax, but the documentation there is no longer being maintained.
 

webdriverguy

Well-Known Member
Joined
May 25, 2017
Messages
334
Location
MA
Tesla Owner
Model 3
Country
Country
#11
The closest solution I can think of would be a simple web page, ideally with no external source files, that called the Tesla API directly from client-side Javascript to generate your token. The page's source code would be concise and readable, so that anyone knowledgeable could easily confirm that it didn't do anything with your credentials other than package them up and send them to Tesla.



Do you have a Mac? If so, open a Terminal window, modify the command below to use your Tesla account's email address and password, and run it:

Code:
curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "grant_type=password" -F "client_id=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384" -F "client_secret=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3" -F "email=xxxxxx@yyyy.zzz" -F "password=********" "https://owner-api.teslamotors.com/oauth/token"
If you have Windows, you can download Curl from here and run the above command from a command-prompt window. I can provide more detailed instructions if needed.

EDIT: I should note that the above command only generates a Tesla API access token, it does not actually return any information about your car. Once you have a token, you will need to make additional API calls (with your access token) to query your car's status. The Apiary documentation linked above can help you generate curl commands for these API calls.
Just an observation I would never post client_id and secret on a public forum.
 

twm01

Active Member
Joined
Jul 30, 2018
Messages
85
Location
Tampa, FL
Tesla Owner
Model 3
Country
Country
#12
Perfect! That's exactly what you want!

Next up is to query your Tesla account to get your vehicle ID. You can do this by using the "vehicles" endpoint, like so:

Code:
curl --include --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles"
That should give you a JSON response with an array of vehicles under your account. For each vehicle, you can see its VIN, configuration codes, current state (asleep / online / etc), and a few other things. Note the value of the "id" property (not the "vehicle_id" property), because you will use it with the following commands.

If you want to get more specific information about your vehicle, you'll need to wake it up if it's currently asleep. You can do this by opening the Tesla app, or you can issue a "wake" command through the API. (Note: replace {vehicle_id} with the value of the "id" property from the previous command.)

Code:
curl --include --request POST --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles/{vehicle_id}/wake_up"
The response to this command may indicate that your vehicle is still asleep, but if you're within earshot of your driveway/garage, you may hear your car make the usual clunking sounds that signal that it's waking up. After a short wait, your car should be awake (and you can confirm this by issuing the same "wake" command and checking the car's status).

Okay, so now your car's awake, how can you find out everything there is to know about its current state? Well, there's a handy endpoint for that:

Code:
curl --include --header "Authorization: Bearer {access_token}" "https://owner-api.teslamotors.com/api/1/vehicles/{vehicle_id}/data"
That will basically give you everything the API knows about the car's current state and configuration. Copy and paste the JSON response into your favorite JSON formatting tool (example) to make it legible, and enjoy!

(Side note: looks like some new fields specific to firmware V9 capabilities have been added recently. Cool!)

For other API endpoints and further reading, Tim Dorr has a more complete, updated version of the API documentation here. The old Apiary site is still useful for quickly generating curl command with the correct syntax, but the documentation there is no longer being maintained.
Thank you @Bokonon !! That gives me exactly what I was looking for. I appreciate you taking the time to give me the exact syntax needed - I knew what I wanted to do, just not how to do it! I hope that others find this as useful as I did.
 

Bokonon

Self-identified Teslaholic
Moderator
M3OC Supporting Member
Joined
Apr 12, 2017
Messages
2,146
Location
Boston
Tesla Owner
Model 3
Country
Country
#13

NOGA$4ME

Top-Contributor
Joined
Sep 30, 2016
Messages
607
Location
Durham, NC
Tesla Owner
Model 3
Country
Country
#14
Just an observation I would never post client_id and secret on a public forum.
Yeah, this is technically not a problem at all. This client_id and secret is for the Tesla app itself, and the values are readily available to anyone with a modest amount of technical knowledge, and have been widely distributed. Just about every non-Tesla app/service makes use of them. It's actually one of worst kept secrets around!

This was discussed at length in a thread that @twm01 would probably find very useful (but which I've lost for the moment). Basically the Tesla app should never have exposed it's secret key (so that it kept ownership of its client-specific privileges) and second, Tesla should make available the mechanism for 3rd party clients to request their own client id, issue secret keys, and allow the user to set a reduced set of permissions for each separate client (and revoke access if necessary). But, alas, there is no such mechanism so everyone just uses the Tesla app's client/secret. The funny thing is that everyone generates access tokens from that key thinking that somehow it's more secure than providing their username/password, when in reality that's not really the case (other than the case where you are re-using your Tesla password for other services).
 
Joined
Aug 15, 2018
Messages
9
Location
San Diego, CA
Tesla Owner
Model 3
Country
Country
#15
This might be a little off-topic, but has anyone use the python library teslajson to get info about their car?

Overall, it works pretty well, but I can't figure out how to 'ping' the car to see if it is sleeping or not. If I do a data request, it wakes up to give me the data. I am having trouble figuring out the command to just get the online state....
 

webdriverguy

Well-Known Member
Joined
May 25, 2017
Messages
334
Location
MA
Tesla Owner
Model 3
Country
Country
#16
This might be a little off-topic, but has anyone use the python library teslajson to get info about their car?

Overall, it works pretty well, but I can't figure out how to 'ping' the car to see if it is sleeping or not. If I do a data request, it wakes up to give me the data. I am having trouble figuring out the command to just get the online state....
Can you please post the link? I am interested in checking it out
 

AmpHog

Active Member
Joined
Oct 28, 2018
Messages
25
Location
NorCal
Tesla Owner
Model 3
Country
Country
#19
As a bit of a Smart Home geek, I'm accessing the Tesla API via SmartThings/webCoRE to generate & maintain a current token, log vehicle information, send charge reminders, and change settings based on time or other triggers, such as routines. My wife and I can even ask Alexa to perform such tasks as warming up and unlocking the car. Still tinkering to figure out the best use of all the capability.

For those not familiar with the webCoRE smartapp, this may look a bit intimidating at first, but in reality any SmartThings user with modest computer skills and a modicum of programming experience can build on the initial work presented here.