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 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 :)
 
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.
 
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?
 
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:
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()
 
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.
 
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" />
 
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
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