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

msgfromside3

Member
Sep 23, 2016
31
11
WA
Same here. Even the official app doesn't work.

EDIT: Actually I can connect to API sometimes but it always returns the vehicle state as unknown. Also data request to any state returns HTTP 408.
 
Last edited:

dpskipper

Developer
Aug 4, 2016
187
44
Australia
I'm not sure what that means. The apiary doc seems to have more commands and parameter settings than the official application. Was there just trial and error? Did someone set up a proxy to capture traffic?
I can't answer that exact question, but I believe that Tim was able to get the client_id by de-compiling the phone app...
 
  • Like
Reactions: apacheguy

timdorr

Model S P90D w/AP3.0
Aug 2, 2012
552
433
Atlanta, Georgia, United States
I can't answer that exact question, but I believe that Tim was able to get the client_id by de-compiling the phone app...

Yep, it was originally some MITM proxy watching. Then I just decompiled the Android APK. In the new React Native version, they actually have a JSON file with all the endpoints listed: Tesla API Endpoints · GitHub

BTW, that shows a new /data endpoint. That gets a combination of all the *_state endpoints so you can get all that info in one call instead of 5 :)
 

rv10driver

Member
Feb 7, 2017
19
12
Boston Area
Yep, it was originally some MITM proxy watching. Then I just decompiled the Android APK. In the new React Native version, they actually have a JSON file with all the endpoints listed: Tesla API Endpoints · GitHub

BTW, that shows a new /data endpoint. That gets a combination of all the *_state endpoints so you can get all that info in one call instead of 5 :)
Thanks, Tim. Nice work. I'm looking forward to Tesla opening up new capabilities.
 

f8K37Sq31

Former Vendor
Jan 1, 2017
398
454
california
Has anyone else noticed that Tesla servers return a "500" status code intermittently? Specifically, if I sent a query once every 10 seconds, about 50% of the queries return the "500" error code.
 

f8K37Sq31

Former Vendor
Jan 1, 2017
398
454
california
I've noticed some new fields in the response to vehicle_state:
'pf = 0'
'pr = 0'
'rhd = 0'
'rt = 0'

Maybe they are not new and I've just noticed them. Does anyone know what they mean?
 

f8K37Sq31

Former Vendor
Jan 1, 2017
398
454
california
Yep, it was originally some MITM proxy watching. Then I just decompiled the Android APK. In the new React Native version, they actually have a JSON file with all the endpoints listed: Tesla API Endpoints · GitHub

BTW, that shows a new /data endpoint. That gets a combination of all the *_state endpoints so you can get all that info in one call instead of 5 :)

Thanks Tim. This JSON file does not include queries like 'vehicle_state'. The servers still respond to 'vehicle_state'. Does this mean that the 'vehicle_state' is being deprecated?
 

hans

P631
Sep 27, 2012
1,132
14
Menlo Park
I've noticed some new fields in the response to vehicle_state:
'pf = 0'
'pr = 0'
'rhd = 0'
'rt = 0'

Maybe they are not new and I've just noticed them. Does anyone know what they mean?

Those aren't new. pf is passenger side front, pr is passenger side rear, rhd is right hand drive, rt is rear trunk. These indicate if the doors are open (1) or not (0) and the rhd is a flag to tell you which side is the driver/passenger side of the car
 
Last edited:

josher32

Member
Oct 29, 2015
275
166
Portland, OR
Fixed it. For those using Swift, its not a query parameter and its not in the body. use session uploadTask

I'm having this exact issue with it resetting to 50% no matter what charge I use. Can you possibly email or respond with he exact Swift Code you used for uploadTask. I can't get it to work on my app for the life of me. Thanks ahead from a grateful beginner!
 

NicB72

Supporting Member
Supporting Member
Jun 25, 2016
100
62
Concord, MA
I'm having this exact issue with it resetting to 50% no matter what charge I use. Can you possibly email or respond with he exact Swift Code you used for uploadTask. I can't get it to work on my app for the life of me. Thanks ahead from a grateful beginner!

Hope this helps.
In essence you can see I set the percent charge to 60% in this example

let intVal:Int = 60
let strVal:String = String(intVal)
var strURL:String = ""
strURL = "https://owner-api.teslamotors.com/api/1/vehicles/" + myTesla.id + "/command/set_charge_limit"
let url = URL(string: strURL)!
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Bearer " + teslaMgr.myTesla.token + "", forHTTPHeaderField: "Authorization")
let json: String = "percent=" + strVal
let jsonData = json.data(using: String.Encoding.utf8)
let session = URLSession.shared
let task = session.uploadTask(with: request as URLRequest, from: jsonData!, completionHandler: { data, response, error in
if let response = response, let data = data {
print(response)
print(String(data: data, encoding: String.Encoding.utf8)!)
} else {
print(error)
}
DispatchQueue.main.async(execute: {
print("Done")
})
})
task.resume()
 

josher32

Member
Oct 29, 2015
275
166
Portland, OR
Hope this helps.
In essence you can see I set the percent charge to 60% in this example

let intVal:Int = 60
let strVal:String = String(intVal)
var strURL:String = ""
strURL = "https://owner-api.teslamotors.com/api/1/vehicles/" + myTesla.id + "/command/set_charge_limit"
let url = URL(string: strURL)!
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Bearer " + teslaMgr.myTesla.token + "", forHTTPHeaderField: "Authorization")
let json: String = "percent=" + strVal
let jsonData = json.data(using: String.Encoding.utf8)
let session = URLSession.shared
let task = session.uploadTask(with: request as URLRequest, from: jsonData!, completionHandler: { data, response, error in
if let response = response, let data = data {
print(response)
print(String(data: data, encoding: String.Encoding.utf8)!)
} else {
print(error)
}
DispatchQueue.main.async(execute: {
print("Done")
})
})
task.resume()


Thanks so much! Really Appreciate it! This worked perfectly. One other question. I'm struggling to parse the data for the read only fields like trying to get the current battery miles. If your app included this any chance you could send this to me. Another option is emailing it to me at [email protected]. I can seem to get the string file but can't seem to get to the dictionary file. Thanks again for your wonderful help.
 

f8K37Sq31

Former Vendor
Jan 1, 2017
398
454
california
I did some MITM proxy-watching hoping to be able to see how the car gets information related to super-charger occupancy.
It turns out that most of the exchanges are done using TLS (encrypted), so they are not visible. There are some xml files that are downloaded to the car, but they seem to be related to traffic condition and map. Here is an excerpt:

<Inrix docType="GetSegmentSpeedInRadius" copyright="Copyright INRIX Inc." versionNumber="9.8" createdDate="2017-03-16T00:33:59Z" statusId="0" statusText="" responseId="ebab3053-3252-4717-98d4-3bad5cd70b71"><SegmentSpeedResultSet coverage="8"><SegmentSpeedResults timestamp="2017-03-16T00:33:59Z"><Segment code="106P05014" type="TMC" speed="29" reference="63" travelTimeMinutes="1.214" /><Segment code="106N05014" type="TMC" speed="73" reference="64" travelTimeMinutes="0.51" />
 

HankLloydRight

No Roads
Supporting Member
Jan 18, 2014
13,111
11,385
Connecticut
I did some MITM proxy-watching hoping to be able to see how the car gets information related to super-charger occupancy.
It turns out that most of the exchanges are done using TLS (encrypted), so they are not visible. There are some xml files that are downloaded to the car, but they seem to be related to traffic condition and map. Here is an excerpt:

<Inrix docType="GetSegmentSpeedInRadius" copyright="Copyright INRIX Inc." versionNumber="9.8" createdDate="2017-03-16T00:33:59Z" statusId="0" statusText="" responseId="ebab3053-3252-4717-98d4-3bad5cd70b71"><SegmentSpeedResultSet coverage="8"><SegmentSpeedResults timestamp="2017-03-16T00:33:59Z"><Segment code="106P05014" type="TMC" speed="29" reference="63" travelTimeMinutes="1.214" /><Segment code="106N05014" type="TMC" speed="73" reference="64" travelTimeMinutes="0.51" />

Have you seen this thread yet? Supercharger Live Status
 
  • Like
Reactions: f8K37Sq31

HankLloydRight

No Roads
Supporting Member
Jan 18, 2014
13,111
11,385
Connecticut
I wonder why Tesla doesn't make that info available outside the car (e.g., through a web interface).

We can speculate, but we'll never know for sure. Well, wk057 might know, but he's not talking.

BTW, to access the live supercharge info, it was just a simple HTTP GET call, but it was over the in-car Tesla VPN and not accessible elsewhere.
 

MartinPF

Member
Mar 16, 2017
46
86
Austria
Just a short note on token expiration / refresh:
While i haven't seen it documented yet, the api seems to support token refreshing. The (documented) request for an authentication token returns a standard oAuth token including a refresh_token. Calling the /oauth/token endpoint with parameters
{ "grant_type", "refresh_token" },
{ "client_id", TESLA_CLIENT_ID },
{ "client_secret", TESLA_CLIENT_SECRET },
{ "refresh_token", <refresh token from previous request>}
seems to work and provides a new access token and a new refresh token.
I haven't got any data yet on howlong/how often it's possible to automatically renew the access token this way, but if this works well it could be helpfull for services where you don't want to store the tesla password and yet keep the api accessible.
 
  • Informative
Reactions: EVCarGUy

Products we're discussing on TMC...

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