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 was using an User-Agent string that was causing issues like that. You might want to see if changing that will help.
Code:
var authHelper = new TeslaAuthHelper("YourUserAgent/1.0");
var tokens = await authHelper.AuthenticateAsync(username, password, mfaCode);
My usage is very similar to the above. I replace "YourUserAgent" with a different alpha string representing my program.

I tried this as well, but same issue:
Code:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66
 
Quick question on token expiration conditions ...

Do all existing valid tokens get invalidated if I reset/update my password for my account on Tesla's site? If so, does this terminate ability for any rest calls even if I have a currently open session?

I'm thinking about updating my account password as I've not changed it for a few months. I'd like to make sure I understand in advance whether this means I'll want to stop my logger program, remove my old token files so it goes back through the full step 1-4 process. Seems like this will be case, but thought I'd ask those of you more expert than I before I fumble around.

Thanks again,
Paul.
 
Is anyone suddenly having problems with login process and pulling data via the API? My logging program today seems to have suddenly quit being able to pull data. I've tried redoing the full login, and appears my script is just hanging in Step 1 seemingly indefinitely waiting for a response to the request to get a login page.
 
Is anyone suddenly having problems with login process and pulling data via the API? My logging program today seems to have suddenly quit being able to pull data. I've tried redoing the full login, and appears my script is just hanging in Step 1 seemingly indefinitely waiting for a response to the request to get a login page.
You can ignore my prior post / question. I figured out my problem. I think my issues were a combination of a couple things, but the major one being need to update my base login authentication routine with some tweaks in Steps 1 and 2 around how the avoid having a User-Agent header that looks like a browser. I'd been running off stored tokens/refresh process for 3~4 months and hadn't pulled in updated login methods since February. Everything is working fine now that I pulled those updates in this morning (morning for me in my part of the world ... evening US time).

For anyone that may be looking for a python script to do this, I continue to base mine off of that posted by encode_engineering on github. If any of you happen to be the people behind that, THANK YOU! I appreciate you continuing to do all the heavy lifting for me.
 
I've been getting a bunch of intermittent errors from the owner API for over a week now. I get both 408 timeout and 503 disconnect errors. Yesterday it was 2% of my queries. Not really causing any problems, other than annoying me with error messages. (I really need to work on the error reporting part of my script!)

Anyway, just thought I'd put this here, in case anyone else is wondering about the same problem.
 
You can ignore my prior post / question. I figured out my problem. I think my issues were a combination of a couple things, but the major one being need to update my base login authentication routine with some tweaks in Steps 1 and 2 around how the avoid having a User-Agent header that looks like a browser. I'd been running off stored tokens/refresh process for 3~4 months and hadn't pulled in updated login methods since February. Everything is working fine now that I pulled those updates in this morning (morning for me in my part of the world ... evening US time).

Yes, I was using a User-Agent string that some Python scripts were using and it was causing my implementation to fail. I now just use the default User-Agent of the Android device and it works fine. (I'm using Automate on android to interact with the API.) I got the User-Agent by doing an HTTP Get request from https://www.whatismybrowser.com/detect/what-is-my-user-agent and scrape the user agent from the HTML output. It's not a standard browser user agent string. If you want me to post one that works and you can use in your scripts, let me know.
 
HI
It seems my account has been locked (doing development of the new authorization) - Does any body know how to get it unlocked? I have waited more than a day and it remains locked
I believe it is the case. I get response 200 from step 2 with :

var messages = {"_":["Your account has been locked"]}; in the response.text -

used to get response 302
 
Have you tried to log into your account directly on-line, not via API calls, but directly through web browser? My only suggestion is to consider doing that, including potentially going through the process to reset your password, to get your account unlocked.

It's been a few months since I had to work through getting my login steps 1~4 working, but I think I ended up only trying a couple times, and if was not being successful, working on something else and not trying about for about 45~60 minutes to stay out of lock-out jail.
 
HI
It seems my account has been locked (doing development of the new authorization) - Does any body know how to get it unlocked? I have waited more than a day and it remains locked
I believe it is the case. I get response 200 from step 2 with :

var messages = {"_":["Your account has been locked"]}; in the response.text -

used to get response 302
Resetting the passwords seems to reset the account
 
If you want me to post one that works and you can use in your scripts, let me know.
Please do! I've been using the postman default and some other ones I've tried, and unsure if it's the User-Agent problem or another. I'm not seeing the <form> element in the HTTP response, but I am getting a 200 OK, so I am trying to eliminate any possible problems.
 
Please do! I've been using the postman default and some other ones I've tried, and unsure if it's the User-Agent problem or another. I'm not seeing the <form> element in the HTTP response, but I am getting a 200 OK, so I am trying to eliminate any possible problems.
Here's link to the python script which I have use as the base of my datalogger routine. It's been just under 3 weeks since I had to do the Step 1~4 full login; since then been running off my saved token. I don't use MFA portion, just base email/password login.

 
Here's link to the python script which I have use as the base of my datalogger routine. It's been just under 3 weeks since I had to do the Step 1~4 full login; since then been running off my saved token. I don't use MFA portion, just base email/password login.

Thanks! I got it working through using a fork off your repo.
 
Please do! I've been using the postman default and some other ones I've tried, and unsure if it's the User-Agent problem or another. I'm not seeing the <form> element in the HTTP response, but I am getting a 200 OK, so I am trying to eliminate any possible problems.
It sounds like your problem got solved, but here's the user agent string from bluestacks:

Dalvik/2.1.0 (Linux; U; Android 7.1.1; ONEPLUS A5000 Build/NMF26X)
 
  • Like
Reactions: 3ngineer
Hi developer friends,

I'm developing an app to start/stop the charge of a Tesla on a schedule.
Before trying to send the command "charge_start" or "charge_stop", I first call a "charge_state" to check the "charging_state" of the vehicle.
For some reason, I got a charging_state=Disconnected even if the car is plugged in to a power outlet.
Have you even experience such a thing?

Thank you!
 
You can use a third-party app, like "Auth app for Tesla" on iOS or "Tesla Tokens" for Android.
Thanks for the suggestion. I'm a little nervous about 3rd party apps like that though. Not that there's anything nefarious about the ones you mentioned. I just like being able to review the source before I start typing in my credentials to someone else's app :)

I got closer with the postman environment posted at GitHub - jdemeyer1/TeslaAPIThruPostman, but at the step 3 it's saying Invalid client ID (I have MFA enabled).
 
Thanks for the suggestion. I'm a little nervous about 3rd party apps like that though. Not that there's anything nefarious about the ones you mentioned. I just like being able to review the source before I start typing in my credentials to someone else's app :)

I got closer with the postman environment posted at GitHub - jdemeyer1/TeslaAPIThruPostman, but at the step 3 it's saying Invalid client ID (I have MFA enabled).
Ok, got you.
Are you sending "ownerapi" for "client_id"at step 3?