All configuration methods return IMyToyotaClient for method chaining (fluent API).
IMyToyotaClient UseCredentials(string username, string password)Sets the MyToyota username and password for authentication.
Parameters:
username- Your MyToyota usernamepassword- Your MyToyota password
Example:
client.UseCredentials("myemail@example.com", "mypassword");IMyToyotaClient UseLogger(Action<string> logger)Provides a custom logging function for debugging and monitoring.
Parameters:
logger- Action to receive log messages
Example:
client.UseLogger(msg => Console.WriteLine($"[Toyota] {msg}"));IMyToyotaClient UseTimeout(int timeoutSeconds)Sets the request timeout in seconds.
Parameters:
timeoutSeconds- Timeout duration in seconds
Example:
client.UseTimeout(60); // 60 second timeoutIMyToyotaClient UseTokenCaching(bool useTokenCaching)Enables or disables token caching to avoid repeated login calls.
Parameters:
useTokenCaching- True to enable caching, false to disable
Example:
client.UseTokenCaching(true);IMyToyotaClient UseTokenCacheFilename(string tokenCacheFilename)Sets the file path for token caching. Only relevant if UseTokenCaching(true).
Parameters:
tokenCacheFilename- File path for storing cached tokens
Example:
client.UseTokenCacheFilename("~/.cache/toyota_tokens.json");Task<bool> LoginAsync(CancellationToken cancellationToken = default)Authenticates with the MyToyota API using configured credentials.
Returns: true if successful, false otherwise
Throws: ArgumentException if credentials not configured
Example:
var success = await client.LoginAsync();
if (!success)
throw new InvalidOperationException("Failed to authenticate");Task<VehiclesModel?> GetVehiclesAsync(CancellationToken cancellationToken = default)Retrieves all vehicles associated with the authenticated user.
Returns: VehiclesModel containing list of vehicles, or null on error
Example:
var vehicles = await client.GetVehiclesAsync();
foreach (var vehicle in vehicles?.Data ?? [])
{
Console.WriteLine($"VIN: {vehicle.Vin}, Name: {vehicle.Nickname}");
}Task<VehicleAssociationResponseModel?> GetVehicleAssociationAsync(CancellationToken cancellationToken = default)Retrieves the vehicle association information for the authenticated user.
Returns: VehicleAssociationResponseModel with association details
Example:
var association = await client.GetVehicleAssociationAsync();Task<ElectricResponseModel?> GetElectricAsync(string vin, CancellationToken cancellationToken = default)Retrieves EV battery and charging information.
Parameters:
vin- Vehicle Identification Number
Returns: ElectricResponseModel with battery and charging status
Example:
var electric = await client.GetElectricAsync("JTHJP5C27D5012345");
Console.WriteLine($"Battery: {electric?.Data?.BatteryLevel}%");
Console.WriteLine($"Charging: {electric?.Data?.IsCharging}");Task<RealtimeStatus?> GetElectricRealtimeStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves real-time EV status data.
Parameters:
vin- Vehicle Identification Number
Returns: RealtimeStatus with real-time data
Example:
var status = await client.GetElectricRealtimeStatusAsync(vin);Task<LocationResponseModel?> GetLocationAsync(string vin, CancellationToken cancellationToken = default)Retrieves the current GPS location of the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: LocationResponseModel with latitude and longitude
Example:
var location = await client.GetLocationAsync(vin);
Console.WriteLine($"Location: {location?.Data?.Latitude}, {location?.Data?.Longitude}");Task<LockStatusResponseModel?> GetLockStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves the lock status of all doors, trunk, and windows.
Parameters:
vin- Vehicle Identification Number
Returns: LockStatusResponseModel with lock statuses
Example:
var lockStatus = await client.GetLockStatusAsync(vin);
Console.WriteLine($"Driver Door: {lockStatus?.Data?.DriverDoor}");
Console.WriteLine($"Trunk: {lockStatus?.Data?.Trunk}");Task<ClimateSettingsResponseModel?> GetClimateSettingsAsync(string vin, CancellationToken cancellationToken = default)Retrieves the current climate control settings configured on the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: ClimateSettingsResponseModel with climate settings
Example:
var settings = await client.GetClimateSettingsAsync(vin);
Console.WriteLine($"Temperature: {settings?.Data?.Temperature}°C");Task<ClimateStatusResponseModel?> GetClimateStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves the current climate control status (running/stopped, cabin temperature).
Parameters:
vin- Vehicle Identification Number
Returns: ClimateStatusResponseModel with current status
Example:
var status = await client.GetClimateStatusAsync(vin);
Console.WriteLine($"Climate Running: {status?.Data?.IsRunning}");
Console.WriteLine($"Cabin Temp: {status?.Data?.CabinTemperature}°C");Task<ClimateControlResponseModel?> StartClimateControlAsync(string vin, CancellationToken cancellationToken = default)Sends a command to start climate control on the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: ClimateControlResponseModel with operation result
Throws: OperationNotSupportedException if vehicle doesn't support this
Example:
var result = await client.StartClimateControlAsync(vin);
if (result?.IsSuccess == true)
Console.WriteLine("Climate control started");Task<ClimateControlResponseModel?> StopClimateControlAsync(string vin, CancellationToken cancellationToken = default)Sends a command to stop climate control on the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: ClimateControlResponseModel with operation result
Example:
var result = await client.StopClimateControlAsync(vin);Task<ClimateControlResponseModel?> RefreshClimateStatusAsync(string vin, CancellationToken cancellationToken = default)Triggers a fresh climate status request from the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: ClimateControlResponseModel with updated status
Example:
var status = await client.RefreshClimateStatusAsync(vin);Task<RemoteCommandResponseModel?> SendRemoteCommandAsync(string vin, RemoteCommandType command, CancellationToken cancellationToken = default)Sends a remote command to the vehicle (lock, unlock, engine start/stop, etc.).
Parameters:
vin- Vehicle Identification Numbercommand- The command to execute (see RemoteCommandType enum)
Returns: RemoteCommandResponseModel with operation result
Supported Commands:
Lock- Lock the vehicleUnlock- Unlock the vehicleEngineStart- Start the engineEngineStop- Stop the engineHazardLights- Toggle hazard lightsHeadlights- Control headlightsTrunk- Open/close trunk
Example:
var result = await client.SendRemoteCommandAsync(vin, RemoteCommandType.Lock);
if (result?.IsSuccess == true)
Console.WriteLine("Vehicle locked");Note: Check RemoteServiceCapabilities on the vehicle to verify support before calling.
Task<RemoteStatusResponseModel?> GetRemoteStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves the current remote service status for the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: RemoteStatusResponseModel with remote service status
Example:
var status = await client.GetRemoteStatusAsync(vin);Task<HealthStatusResponseModel?> GetHealthStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves vehicle health diagnostics information.
Parameters:
vin- Vehicle Identification Number
Returns: HealthStatusResponseModel with health status
Example:
var health = await client.GetHealthStatusAsync(vin);Task<TelemetryStatusResponseModel?> GetTelemetryStatusAsync(string vin, CancellationToken cancellationToken = default)Retrieves vehicle telemetry data.
Parameters:
vin- Vehicle Identification Number
Returns: TelemetryStatusResponseModel with telemetry data
Example:
var telemetry = await client.GetTelemetryStatusAsync(vin);Task<TripsResponseModel?> GetTripsAsync(string vin, DateOnly from, DateOnly to, bool route = false, bool summary = true, int limit = 50, int offset = 0, CancellationToken cancellationToken = default)Retrieves trip history for the vehicle within a date range.
Parameters:
vin- Vehicle Identification Numberfrom- Start date for trip historyto- End date for trip historyroute- Include detailed route data (default: false)summary- Include trip summary (default: true)limit- Maximum number of trips to return (default: 50)offset- Pagination offset (default: 0)
Returns: TripsResponseModel with trip data
Example:
var trips = await client.GetTripsAsync(
vin,
from: DateOnly.FromDateTime(DateTime.Now.AddDays(-7)),
to: DateOnly.FromDateTime(DateTime.Now),
route: true,
limit: 100
);
foreach (var trip in trips?.Data ?? [])
{
Console.WriteLine($"Trip: {trip.StartTime} - {trip.Distance}km");
}Task<ServiceHistoryResponseModel?> GetServiceHistoryAsync(string vin, CancellationToken cancellationToken = default)Retrieves service and maintenance records for the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: ServiceHistoryResponseModel with service records
Example:
var history = await client.GetServiceHistoryAsync(vin);Task<NotificationsResponseModel?> GetNotificationsAsync(string vin, CancellationToken cancellationToken = default)Retrieves recent notifications for the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: NotificationsResponseModel with notifications
Example:
var notifications = await client.GetNotificationsAsync(vin);Task<DrivingStatisticsResponseModel?> GetDrivingStatisticsAsync(string vin, CancellationToken cancellationToken = default)Retrieves driving statistics and eco-scores for the vehicle.
Parameters:
vin- Vehicle Identification Number
Returns: DrivingStatisticsResponseModel with statistics
Example:
var stats = await client.GetDrivingStatisticsAsync(vin);
Console.WriteLine($"Eco Score: {stats?.Data?.EcoScore}");
Console.WriteLine($"Driving Events: {stats?.Data?.DrivingEvents}");The library throws specific exceptions for different scenarios:
AuthenticationException- Login or token validation failedApiException- API returned an error or unexpected responseOperationCanceledException- Operation was cancelled via CancellationTokenTimeoutException- Operation exceeded configured timeoutOperationNotSupportedException- Vehicle doesn't support the requested operationArgumentException- Invalid arguments providedArgumentNullException- Required argument is null
All API methods return model classes or null on error. Response models follow this pattern:
public class ResponseModel<T>
{
public T? Data { get; set; }
public bool IsSuccess { get; set; }
public string? ErrorMessage { get; set; }
public DateTime Timestamp { get; set; }
}Always check for null or IsSuccess before accessing Data.