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.
If you find a solution let me know.

Also note there's a pull request for the fix for the hjesper's teslams code, though it still isn't working for me. But that could be something on my side.

Hjesper teslams works fine for me. I modified some stuff in the streaming file to handle the napping/sleeping of the car. I guess when he implemented it, teslaservers would have responded in a different way.

Re token for streaming, attention this isnt the authentication token, but another token which changes every couple minutes. You get this token from teslams vehicle requests. I think streaming.js handles this already. I ll check my version vs hjespers one

For streaming and teslaall i use username and token in the json.config file. This token is the one you retrive with ---print_token from teslacmd . Authentication token.

Streaming requests work still fine, the only thing you would need to change is adding "headers" specifying a user-agent in the teslams.js post requests when u authenticate with username&pass. This has changed 1 week ago
 
Last edited:
Help!

I have written my own mini-app that uses the “unofficial” Tesla api. It’s been working more or less continuously for the past year or so. However about 7 days ago it suddenly started to give me a permanent “503” error response when I try to do the initial login. So far I have been unable to find out why.

Any ideas anybody?

(I haven’t changed my login credentials lately).

Thanks for any suggestions as to what I can try next to solve this issue.
 
Help!

I have written my own mini-app that uses the “unofficial” Tesla api. It’s been working more or less continuously for the past year or so. However about 7 days ago it suddenly started to give me a permanent “503” error response when I try to do the initial login. So far I have been unable to find out why.

Any ideas anybody?

(I haven’t changed my login credentials lately).

Thanks for any suggestions as to what I can try next to solve this issue.

Try adding a Use-Agent header
 
Hjesper teslams works fine for me. I modified some stuff in the streaming file to handle the napping/sleeping of the car. I guess when he implemented it, teslaservers would have responded in a different way.

With the pull request changes that were recently submitted I was able to get it working. Thanks.

I ll check my version vs hjespers one
What is your version? Just something you did privately or something you have on a repo somewhere?

Thanks
 
Help!

I have written my own mini-app that uses the “unofficial” Tesla api. It’s been working more or less continuously for the past year or so. However about 7 days ago it suddenly started to give me a permanent “503” error response when I try to do the initial login. So far I have been unable to find out why.

Any ideas anybody?

(I haven’t changed my login credentials lately).

Thanks for any suggestions as to what I can try next to solve this issue.

What is your app written in?
I've found that certain calls require more or less in the headers based on if you cURL them or use something else.
 
I have tried using this:

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

.....but I then receive the following error:
The 'User-Agent' header must be modified using the appropriate property or method.
Parameter name: name

Any suggestions?
That’s sounds more like an SDK error. I don’t think that error is coming from Tesla API.
What are you writing the app in?
 
With the pull request changes that were recently submitted I was able to get it working. Thanks.


What is your version? Just something you did privately or something you have on a repo somewhere?

Thanks

yes I did some modification saved locally dont have a repo.
the napping wasnt handled correctly when I downloaded the code (around 6 month ago), i.e. the car would not get out of napping if you stopped, lets say for 5-10min, and drove again.
also there isnt a handling to quit tesla_poll when the car is actually sleeping.
I dont know if this is now fixed, havent checked any recent code version, altough i thought there wasnt any code amendment for the past 2 years.
my guess is that teslaservers now respond differently than they did when hjspers implemented streaming.js

attaching my modified version of it (changed extension otherwise wouldnt let me upload a *.js file).
I didnt want to waste too much time on this so just fixed napping/sleeping, i m pretty sure many things could be rewritten.


Is there an endpoint that contains current kWh capacity? I want to pull data before and after a drive and see kWh used... This figure is available from trip computer (kWh used)

there isn't any data telling us the capacity in kwh but there is the ideal and rated battery range in miles(estimated). you would need to convert the estimated miles with rated wh/miles to get khw. not sure how accurate that is though.
 

Attachments

  • streaming.js.txt
    28.7 KB · Views: 96
Last edited:
yes I did some modification saved locally dont have a repo.
the napping wasnt handled correctly when I downloaded the code (around 6 month ago), i.e. the car would not get out of napping if you stopped, lets say for 5-10min, and drove again.
also there isnt a handling to quit tesla_poll when the car is actually sleeping.
I dont know if this is now fixed, havent checked any recent code version, altough i thought there wasnt any code amendment for the past 2 years.
my guess is that teslaservers now respond differently than they did when hjspers implemented streaming.js

attaching my modified version of it (changed extension otherwise wouldnt let me upload a *.js file).
I didnt want to waste too much time on this so just fixed napping/sleeping, i m pretty sure many things could be rewritten.




there isn't any data telling us the capacity in kwh but there is the ideal and rated battery range in miles(estimated). you would need to convert the estimated miles with rated wh/miles to get khw. not sure how accurate that is though.
Yeah I can calculate that by (range delta) / 310 × 78 . This is a decent approximation for the Model 3 assuming 78 kWh available pack and 310 rated milage.. . But the range can be affected by temperature so since it is exposed in the GUI I was hoping it was available in the API for more accurate measurements
 
Yeah I can calculate that by (range delta) / 310 × 78 . This is a decent approximation for the Model 3 assuming 78 kWh available pack and 310 rated milage.. . But the range can be affected by temperature so since it is exposed in the GUI I was hoping it was available in the API for more accurate measurements

in model 3 you have remaining capacity exposed in the GUI??
try the get_charge_state endpoint from teslams.js maybe for model 3 it returns more info than for model S.
hjespers/teslams

if you download this framework you can access by teslacmd -c -u username -p password



the capacity and remaining capacity can be retrieven from the CAN Bus

gonna crosspost.
Very cheap CAN BUS reader with Arduino UNO, Battery Voltages Example
 
Did anyone manage to update their homeseer integration? I was using urlaction to drive my plugin, but as I understand url is not supported in the tesla API anymore, only JSON format and therefor I can not use urlaction. Did anyone find a fix for this yet?
 
So I've noticed the streaming tokens returned by the APIs lately are sometimes invalid. This is easily observable by sniffing the official app's network traffic and every so often the tokens returned are invalid such that attempting to summon or access telemetry (location screen) will repeatedly fail with 401 unauthorized "can't validate password".

I'm still trying to safely conclude what the root issue is, but after extensive testing all signs point to the conclusion that this is a relatively new issue introduced on Tesla's server-side in the past few months. If this is the case then it sucks as the best you can do now is cache all your streaming tokens and hope one works eventually. Would love to be wrong on this one!

I've noticed this, too. Did you ever find any solution? What does that app do in this situation?
 
  • Like
Reactions: SG57
After the change, can anyone tell me what needs to be changed?
I pulled this straight out from the rest api:


Code:
Dim request = TryCast(System.Net.WebRequest.Create("https://owner-api.teslamotors.com/oauth/token"), System.Net.HttpWebRequest)

request.Method = "POST"

request.ContentLength = 0
Dim responseContent As String
Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
  Using reader = New System.IO.StreamReader(response.GetResponseStream())
    responseContent = reader.ReadToEnd()
  End Using
End Using

What I have gathered is that there needs a new user-agent attribute? But by adding this the server wont respond. So, I guess there are more changes? Anyone know why the restAPI is outdated by the way? Did he not care for it anymore?
 
in model 3 you have remaining capacity exposed in the GUI??...try the get_charge_state endpoint from teslams.js maybe for model 3 it returns more info than for model S...the capacity and remaining capacity can be retrieven from the CAN Bus...Very cheap CAN BUS reader...
Keep in mind that you can't access the CANBus in the Model 3 without taking apart your dash and tapping the CAN wires. The diagnostic port is not user accessable at the moment. This might also be true for MCU2 on the S.X.
 
To test the websocket service, you can use this curl command :
Code:
curl --user 'USERNAME:TOKEN' -i -N  --header "Sec-WebSocket-Key: SGVsbG8sIHevcmxkIQ==" -H "Sec-WebSocket-Version: 13" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: streaming.vn.teslamotors.com" -H "Origin: https://streaming.vn.teslamotors.com" https://streaming.vn.teslamotors.com/connect/VEHICLE_ID

Change the USERNAME, TOKEN and VEHICLE_ID to match your info.
Note that you ONLY get this information now at very low frequency :
Code:
{"latitude":45.377188,"longitude":-73.60919,"msg_type":"vehicle_data:location"}
It seem to have happen to model 3 only at first, and it seem to be rolling out to model S and X as well now !

I hope it just an error on tesla part, but I feel that tesla is looking to lower their 3g data usage so the good streaming data day might be over !!! I wish we could have had some headup from Tesla about this, giving time to give a solution or inform user of site like mine, teslalog.com.


It appears I am using all the correct variables but getting the "{"error":"vehicle not found (404)"}" error. I've tried on several different models and used my access token and the first vehicle token. Is there an issue currently? I tried Model S with 2018.34.1 & Model X with 2018.28.5 and model 3 just to try but same error. I'd love to get this working. Any ideas on what could be going wrong?
 
It appears I am using all the correct variables but getting the "{"error":"vehicle not found (404)"}" error. I've tried on several different models and used my access token and the first vehicle token. Is there an issue currently? I tried Model S with 2018.34.1 & Model X with 2018.28.5 and model 3 just to try but same error. I'd love to get this working. Any ideas on what could be going wrong?

I came here with the same issue -- I can get a bearer token and I can list vehicles, but none of the vehicle-specific APIs are working for me. I get:

{
"response": null,
"error": "not_found",
"error_description": ""
}​

for any API whether using vehicle_id or id as returned from ListVehicles.

e.g.

curl --include \
--header "Authorization: Bearer XXXXXXX" \
--header "User-Agent: Mozilla/5.0 (Linux; Android 9.0.0; VS985 4G Build/LRX21Y; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36" \
--header "X-Tesla-User-Agent: TeslaApp/3.4.4-350/fad4a582e/android/9.0.0" \
https://owner-api.teslamotors.com/api/1/vehicles/YYYYYYY/data_request/charge_state

for each YYYYYYY of id and vehicle_id