TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker and becoming a Supporting Member. For more info: Support TMC

Tesla API Token Generator

Discussion in 'Model S' started by MarcusMaximus, Jan 6, 2017.

Tags:
  1. Duke-U

    Duke-U Member

    Joined:
    Jul 21, 2016
    Messages:
    566
    Location:
    Tilburg, Netherlands
    I wonder, has nobody compiled this into a simple webpage or program to make this accessible for simple non-nerds? I think you solve a great security issue here...
     
  2. Bernie298

    Bernie298 BernardS

    Joined:
    Jul 24, 2016
    Messages:
    164
    Location:
    Beuningen
    @Duke-U At this moment I am coding a simple webpage to create a token for third party applications.
    At this moment I used it for own purpose, I am rewriting it for public use. I'll keep you in touch
     
    • Like x 1
  3. Frankman60

    Frankman60 Member

    Joined:
    Jun 21, 2016
    Messages:
    292
    Location:
    San Diego, CA
    Can anyone that is familiar with Python 3.6 provide some instruction how to run the Teslatoken.py script that was posted in this thread? Perhaps the OP can jump in? I realize that there are other web based tools to do this instead of software like Python but using those third party websites brings up other security concerns.
     
  4. BigTonyTones

    BigTonyTones Member

    Joined:
    Nov 28, 2016
    Messages:
    369
    Location:
    Los Angeles
  5. JTO6543

    JTO6543 New Member

    Joined:
    Sep 14, 2017
    Messages:
    3
    Location:
    Charlotte, NC
    Any more on how to execute the Python script that was posted for anyone new to Python?
     
  6. Iluvpcs

    Iluvpcs Supporting Member

    Joined:
    May 11, 2015
    Messages:
    121
    Location:
    Grand Rapids, MI
    FYI love postman. It has a converter to change to ruby, python, etc its https requests to about a dozen different languages. Been using that tool for years to create bash / curl and use in workflows for some low level automation. Tokens are nice as you can share them with others and depending on access they will not ever have your username / Password. Unless of course the token grants that in the host system for instance.


    Sent from my iPhone
     
    • Helpful x 1
  7. JTO6543

    JTO6543 New Member

    Joined:
    Sep 14, 2017
    Messages:
    3
    Location:
    Charlotte, NC
    As in, I downloaded Python and installed it (from Download Python ). Then I open IDLE. Then, what command do I run to execute teslatoken.py and pass in a username and password?
     
  8. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,599
    Location:
    Somewhere
    I have a simple curl command I use, I can share it if it's worth it to folks.
     
    • Like x 1
  9. KarenRei

    KarenRei KarenRei KarenRei KarenRei KarenRei KarenRei

    Joined:
    Jul 18, 2017
    Messages:
    2,541
    Location:
    Iceland
    #29 KarenRei, Sep 18, 2017
    Last edited: Sep 18, 2017
    A question question about the API - is there no way to get tire pressure? I was reading through the docs:

    Tesla Model S JSON API · Apiary

    ... and see nothing concerning it. Also nothing to read or adjust the nav. Are there more parameters that just aren't documented there?
     
  10. dsm363

    dsm363 Roadster + Sig Model S

    Joined:
    May 17, 2009
    Messages:
    18,321
    Location:
    Nevada
    How do you use this app to create the token? On a Mac and trying to figure this out. Thanks.
     
  11. Klaus

    Klaus Member

    Joined:
    Apr 20, 2013
    Messages:
    491
    On the Mac you can use Platypus or Automator to wrap a shell script into an app. I use Platypus
     
    • Informative x 1
  12. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,599
    Location:
    Somewhere
    Here you go, just replace <USERNAME> with your username for Tesla owner login and same for <PASSWORD>

    curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "grant_type=password" -F "client_id=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384" -F "client_secret=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3" -F "email=<USERNAME>" -F "password=<PASSWORD>" "https://owner-api.teslamotors.com/oauth/token"
     
  13. JTO6543

    JTO6543 New Member

    Joined:
    Sep 14, 2017
    Messages:
    3
    Location:
    Charlotte, NC
    @BigD0g thanks for the code. However when I try to execute in mac Terminal with a bogus username and password to test, I get:

    curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F "grant_type=password" -F "client_id=81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384" -F "client_secret=c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3" -F "[email protected]” -F "password=1234password” "https://owner-api.teslamotors.com/oauth/token"

    {"response":"{\"message\"=>\"object_reference_not_set_to_an_instance_of_an_object.\",_\"stacktrace\"=>\"___at_myteslawebservice.controllers.authenticationcontroller.<authenticate>d__1.movenext"}

    Any other tips you can give to someone new to this?
     
  14. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,599
    Location:
    Somewhere
    It will only work with a valid username / password on a valid tesla owner account.
     
  15. jto654

    jto654 Member

    Joined:
    Mar 30, 2015
    Messages:
    6
    Location:
    Charlotte, NC
    Ok it just seems weird bc the error says " object_reference_not_set_to_an_instance_of_an_object " not "invalid username/password
     
  16. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,599
    Location:
    Somewhere
    I suspect that is Tesla playing games to prevent people discovering someone's username, and then being able to try to figure out their pwd. From what I can tell Tesla doesn't lock your account after 3 attempts, so if you can figure out the username, you can just go hog wild trying to figure out the password.
     
  17. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,599
    Location:
    Somewhere
    python teslatoken.py -e <mytesla email> -p <mytesla password>
     
  18. FuzzyBabyDucks

    FuzzyBabyDucks New Member

    Joined:
    Sep 27, 2017
    Messages:
    1
    Location:
    Connecticut
    Its not python3 code so it'll run into a runtime error when trying to use it with python 3.

    attached is an updated .zip with both python 2 and 3 versions:
     

    Attached Files:

  19. cconnoruk

    cconnoruk New Member

    Joined:
    Sep 30, 2017
    Messages:
    1
    Location:
    UK
    Thank you this one worked perfectly for me :).
     
    • Helpful x 1
    • Like x 1
  20. Requiem

    Requiem Member

    Joined:
    Apr 8, 2015
    Messages:
    41
    Location:
    Norway
    Thanks! This was the easiest method to me :)
     
    • Like x 1
    • Disagree x 1

Share This Page

  • 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