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 or making a Paypal contribution here: paypal.me/SupportTMC

REST API Tools and Apps

Discussion in 'Wiki' started by Wiki, Aug 30, 2013.

Thread Status:
The first post in this thread is a WikiPost, and can be edited by anyone with the appropriate permissions.
  1. Wiki

    Wiki Member

    Joined:
    Mar 21, 2016
    Messages:
    26
    This is a simple user contributed list of tools and applications that implement the unofficial Tesla Model S REST API

    Programming Libraries by Language - These toolkits should help developers get started in the language of their choice.

    Python -
    PyTesla
    JavaScript - TeslaMS
    Java - TeslaClient
    C#/.Net - Teslalib
    Ruby - tesla-api
    PHP/MySQL - Tesla Mobile

    Mobile Applications - Tesla provides official mobile apps for Android and Apple iOS

    Windows Mobile - Tesla Connect, and Tesla Companion
    BlackBerry - Model S for Blackberry


    Desktop Applications - Download and run these on your laptop, home, or office computer to check up on, and control your car without the need to use your phone

    VisibleTesla - runs on any computer with Java


    Basic Tools - Stuff to get computer literate non-programmers in control of their Tesla

    cURL - Many operating systems come with this handle utility already installed. The REST API can be called using various "curl" commands from your computers command shell (terminal).

    Example curl command to login to Tesla and get a cookie with your authentication token. Replace "USERNAME" and "PASSWORD" with your actual Tesla website login and password.

    Code:
    curl -c cookies.txt -d "user_session[email]=USERNAME&user_session[password]=PASSWORD" https://portal.vn.teslamotors.com/login
    Example curl command to get the vehicle information (including "id" needed for all other commands)

    Code:
    curl -b cookies.txt https://portal.vn.teslamotors.com/vehicles
    Example curl command to start charging (replace "ID" with the three to five digit "id" of your car, as returned by the previous command)

    Code:
    curl -b cookies.txt https://portal.vn.teslamotors.com/vehicles/ID/command/charge_start
    Example curl command to check the current charge state

    Code:
    curl -b cookies.txt https://portal.vn.teslamotors.com/vehicles/ID/command/charge_state
    Example curl command to get data from the Streaming API. Replace "USERNAME" with your actual Tesla website login (as in the REST API). Replace TOKEN with the first of the two tokens returned in the output of the previous curl command for vehicle information. Replace LONG_VEHICLE_ID with the 10 digit "vehicle_id" also returned with the vehicle information (note that this is different than the "id" used in the REST API calls).

    Code:
    curl -u USERNAME:TOKEN https://streaming.vn.teslamotors.com/stream/LONG_VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range,heading
    Streaming data will not return for up to 2 minutes if the car is not moving. When moving the data will return at 4 updates per second (i.e. samples every 250 milliseconds) and stop after two minutes. When the two minute long poll returns, you will need to poll again for another two minutes of streaming data. This is a normal "HTTP long polling" method of streaming data.

    The first field returned is a timestamp in the form of number of seconds since the birthdate of Unix (midnight, January 1st, 1970).

    Tokens rollover or expire every 15 minutes (at exactly the top of the hour :00, or 15, 30, and 45 past the hour). Since there are two tokens, the first one in the list will last for up to 30 minutes.

    If no tokens are present, you will need to wake up the car using the REST API call for wake_up in order to get new tokens.Replace "ID" with the three digit "id" of your car as in the previous REST commands.

    Code:
    curl -b cookies.txt https://portal.vn.teslamotors.com/vehicles/ID/command/wake_up

    Fiddler - The free web debugging proxy for any browser, system or platform

     
  2. Psy-Q

    Psy-Q New Member

    Joined:
    Jun 1, 2014
    Messages:
    1
    Location:
    Switzerland
  3. hans

    hans P631

    Joined:
    Sep 27, 2012
    Messages:
    1,123
    Location:
    Menlo Park
    Added to the Wiki
     
  4. gglockner

    gglockner Member

    Joined:
    Nov 7, 2013
    Messages:
    140
    Location:
    Bellevue WA
  5. jsgoecke

    jsgoecke Member

    Joined:
    Nov 20, 2015
    Messages:
    11
    Location:
    Half Moon Bay, CA
    Is this definition still valid, or is there a new spec? I am trying to use the Ruby lib, my own tests, etc, and with a valid email/password I get 500 backs from the Tesla servers.
     
Thread Status:
The first post in this thread is a WikiPost, and can be edited by anyone with the appropriate permissions.

Share This Page