Tesla-API 1.1.3

dotnet add package Tesla-API --version 1.1.3
NuGet\Install-Package Tesla-API -Version 1.1.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tesla-API" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tesla-API --version 1.1.3
#r "nuget: Tesla-API, 1.1.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tesla-API as a Cake Addin
#addin nuget:?package=Tesla-API&version=1.1.3

// Install Tesla-API as a Cake Tool
#tool nuget:?package=Tesla-API&version=1.1.3

GitHub Workflow Status Release Version Nuget Version Nuget Downloads

Buying a Tesla? Get 1,000 miles of free supercharging with my referral code.

C# Tesla API Client

This is an unofficial .NET client implementation of the Tesla JSON API used by the Android and iOS apps. The API provides functionality to monitor and control the Tesla vehicles remotely.

Tim Dorr API Documentation

API Documentation GitHub

Installation

.NET CLI

dotnet add package 'Tesla-API'

Setup

Dependency Injection

When registering your services, call the method below to allow all required services to be dependency injected.

services.AddTeslaApi();

Usage

To make a request with the Tesla API, you'll need to create a HttpClient and set the User-Agent header to an identifier for your application.

Authenticating with Tesla

Follow the standard OAuth process as documented by Tim Dorr to get an access token. After getting an access token, add it to the Authorization header on the HttpClient, which is passed into data API calls.

You can use the TeslaAuth package that provides a .NET implementation to obtain a refresh token.

Example Code

public class TeslaService
{
    private readonly ITeslaAPI _teslaAPI;
    private readonly HttpClient _client = new HttpClient();
    
    /// <summary>
    /// Initializes a new instance of the <see cref="TeslaService"/> class.
    /// </summary>
    /// <param name="teslaClient">The TeslaAPI client.</param>
    public TeslaService(ITeslaAPI teslaAPI)
    {
        _teslaAPI = teslaAPI;
        _client.DefaultRequestHeaders.Add("User-Agent", "MyApplication");
    }
    
    /// <summary>
    /// Get all vehicles in the user's account.
    /// </summary>
    /// <returns>A list containing~~~~ all vehicles.</returns>
    public async Task<List<Vehicle>> GetVehiclesAsync(string clientId, string clientSecret, string bearerToken)
    {
        TeslaAccessToken accessToken = await _teslaAPI.GetAccesTokenAsync(_client, clientId, clientSecret, bearerToken);
        _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken.AccessToken}");
        
        return await _teslaAPI.GetAllVehiclesAsync(_client);
    }
}

Tests

To run tests you will need a Tesla access token along with additional vehicle and/or energy site information. These tests make actuall calls to the Tesla API, thus Tesla products are required on your account. i.e. to test the vehicle endpoints, you have to have a vehicle registered to your Tesla account.

  1. Generate a Tesla access token. There's a handy Chrome plugin for this.
  2. Copy the appsettings.json file to appsettings.Development.json and fill in the Tesla.AccessToken field along with any other fields required by the test(s) you want to run.
  3. Run the test(s).
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 534 1/14/2024
1.1.2 343 12/8/2023
1.1.1 1,457 6/4/2023
1.1.0 136 5/18/2023
1.0.8 753 8/8/2022
1.0.7 534 3/24/2022
1.0.6 384 3/23/2022
1.0.5 401 3/15/2022
1.0.4 388 4/18/2021
1.0.3 2,430 3/1/2021
1.0.2 317 2/6/2021
1.0.1 350 1/21/2021
1.0.0 331 1/3/2021