Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Tesla Owners API v3 enabled

This site may earn commission on affiliate links.
TEG just upgraded to 20.49.0 and previously open TEG API calls now require authentication. Anyone have updated info on authenticating to the TEG (not the Internet API as discussed above)?
I am also looking for this information too. My PW just upgraded to 20.49.0 and now my Powershell scripts that access all local API no longer works. Getting error code 403: Unable to GET to resource: User does not have adequate access rights.
 
OK, so looks like you need to POST to https://TEG_IP/api/login/Basic with JSON: {"username": "customer", "email": "TEG_EMAIL", "password": "TEG_PASSWORD", "force_sm_off": false}. This should return two Set-Cookie headers (AuthCookie, UserRecord). Include these cookies when calling TEG API (e.g., /api/meters/aggregates).
Yes, it works! Thank for your help.

P.S. I didn't include "force_sm_off". I think it only applies to "installer". No need for "customer".
 
Last edited:
Ugh, I literally got the word today to flip on my solar, and afterwards I looked at my Grafana dashboards and they were blank...

So does anyone have any advice on how to get these cookies into Telegraf for pulling data?
Cookies seem so backwards to use for authentication this move has really surprised me.
 
So does anyone have any advice on how to get these cookies into Telegraf for pulling data?
Here's what worked for me – edit telegraf.conf and in the [[inputs.http]] block, after method="GET", add:

headers = {"Cookie" = "Auth_Cookie=###;UserRecord=###"}

replacing ### with the appropriate authentication cookies retrieved per above post. I'm yet to automate this so the auth cookies are auto-retrieved from another process that monitors the TEG's grid status.
 
Here's what worked for me – edit telegraf.conf and in the [[inputs.http]] block, after method="GET", add:

headers = {"Cookie" = "Auth_Cookie=###;UserRecord=###"}

replacing ### with the appropriate authentication cookies retrieved per above post. I'm yet to automate this so the auth cookies are auto-retrieved from another process that monitors the TEG's grid status.

I've updated my scripts to just use the AuthCookie (no underscore) and no UserRecord, works fine as far as I can tell.

I'm also refreshing the token every hour as it does expire - I was getting 401s after a few hours of using the same token.
 
  • Helpful
Reactions: bmah
I'm confused, the token I generated from owner-api.teslamotors.com a few weeks ago is still working fine today to import 5 minute energy data from Tesla. Is this what's broken when the TEG updates to the newer firmware or is it only broken if you're going straight to the TEG locally?
 
I'm confused, the token I generated from owner-api.teslamotors.com a few weeks ago is still working fine today to import 5 minute energy data from Tesla. Is this what's broken when the TEG updates to the newer firmware or is it only broken if you're going straight to the TEG locally?
My understanding is that what will no longer work is refreshing the access token when it expires. This is separate from the new firmware that requires authenticating to get to the aggregate and soe numbers locally.
 
My understanding is that what will no longer work is refreshing the access token when it expires. This is separate from the new firmware that requires authenticating to get to the aggregate and soe numbers locally.

So is there a fix for this or am I screwed once my token expires? Also, is this only broken if you'r using 2fa which I'm not?

EDIT: I get it. New process which works NOW if you don't need to deal with 2FA.
 
Last edited:
My remote API token appears to have expired at the same time as the 20.49 upgrade without 2FA The local API started requiring a token after the upgrade.

The fix in both cases is to use the new auth mechanism for getting tokens as discussed above.
 
Anyone use HomeAssistant for this mode switching? Volunteers are still sorting out the code (Borrowing from the GitHub posted in post 1 I believe) but still not complete.

Add support for Tesla Powerwall

It was working great before. I had an automation set up where the PW went into backup mode when the car charged at night so as to not drain them and then when done, switch back. I monitored the home consumption to do this.
 
OK, so looks like you need to POST to https://TEG_IP/api/login/Basic with JSON: {"username": "customer", "email": "TEG_EMAIL", "password": "TEG_PASSWORD", "force_sm_off": false}. This should return two Set-Cookie headers (AuthCookie, UserRecord). Include these cookies when calling TEG API (e.g., /api/meters/aggregates).
Thanks! My local API access just stop working.

This is after I had just finished the OAuth2 flow for my remote API access ...
 
Thanks! My local API access just stop working.

This is after I had just finished the OAuth2 flow for my remote API access ...
Just had ours update as well yesterday afternoon, and, as expected, the API stopped working (I also had to go through a re-registration, which was unexpected.)

I also feel like they should not be sending updates as the did to me while storm watch is active. While these updates should be pretty smooth and transparent to the user (other than the API change here,) it seems like a bad time to risk any possible issues.
 
  • Like
Reactions: Ulmo
So I was just upgraded to 20.49.0 and was a little peeved by the change to the local API which broke my monitoring. I ended up coding around it but was wondering if anyone here knows how long the AuthCookie and UserRecord cookies are valid for?

I see the expiration for these are marked as session but what is the max life of a session for the gateway? At the moment, I'm actually make an auth call and getting new cookies right before every GET request for the gridstatus (these go every 20 seconds) but my concerns with this are:
1) Overhead/timing
2) Maxing out the sessions the gateway can handle

I suppose I could just keep reusing the same cookie until hitting a 403 response and then make the auth call and try again. Just wondering if anyone know if this is something that would likely happen hourly, daily, weekly, monthly, etc.

Thanks.
 
So I was just upgraded to 20.49.0 and was a little peeved by the change to the local API which broke my monitoring. I ended up coding around it but was wondering if anyone here knows how long the AuthCookie and UserRecord cookies are valid for?.

I used post #48 from @gpez above as a guide to updating my own code, which I just got working this evening.

Bruce.
 
  • Like
Reactions: Ulmo