Tesla-API
1.0.5
See the version list below for details.
dotnet add package Tesla-API --version 1.0.5
NuGet\Install-Package Tesla-API -Version 1.0.5
<PackageReference Include="Tesla-API" Version="1.0.5" />
<PackageVersion Include="Tesla-API" Version="1.0.5" />
<PackageReference Include="Tesla-API" />
paket add Tesla-API --version 1.0.5
#r "nuget: Tesla-API, 1.0.5"
#:package Tesla-API@1.0.5
#addin nuget:?package=Tesla-API&version=1.0.5
#tool nuget:?package=Tesla-API&version=1.0.5
Buying a Tesla? Get 1,000 miles of free supercharging with my referral code.
C# Tesla API Client
This is an unofficial .NET 5 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.
Installation
From Powershell
Nuget-Install 'Tesla-API'
.NET CLI
dotnet add package 'Tesla-API'
Setup
Setup Dependency Injection
In the Startup.cs file, add the following to the ConfigureServices method to allow the TeslaAPI to be dependency injected.
services.AddScoped<ITeslaAPI, TeslaAPI>();
Making a Request
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
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>Returns a list of 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);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.1)
-
net5.0
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.