Connect to your Tesla through an API!

Daniel Vega
Jun 15 · 3 min read

Getting Started: Get the client_id and client_secret

Creating the Authentication headers

from rauth import OAuth2Service
import json
service = OAuth2Service(
client_id = '<insert client key here>',
client_secret = '<insert client secret here>',
access_token_url = "https://owner-api.teslamotors.com/oauth/token",
authorize_url = "https://owner-api.teslamotors.com/oauth/token",
base_url = "https://owner-api.teslamotors.com/",
)
email = '<insert Tesla email here>'
password = '<insert Tesla password here>'
data = {"grant_type": "password",
"client_id": '<insert client key here>',
"client_secret": '<insert client secret here>',
"email": email,
"password": password}
session = service.get_auth_session(data=data, decoder=json.loads)
access_token = session.access_token
my_session = service.get_session(token=access_token)

Get a list of Vehicles

url = 'https://owner-api.teslamotors.com/api/1/vehicles/'
vehicles = my_session.get(url).json()
vehicles = my_session.get(url).json()['response'][0]
Car_1 = vehicles['id_s'] #id_s is the id as a string

Get Vehicle Information

'/api/1/vehicles/{}/vehicle_data'.format(Car_1)

Future Vision

A publication centered around high quality storytelling

Daniel Vega

Written by

Future Vision

A publication centered around high quality storytelling