You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use for OAuth 2.0, Azure Managed Identity, or any rotating-token scenario:
builder.Services.AddSamsaraClient(options =>{options.TokenProvider=async ct =>{// Fetch token from your identity provider or secrets managerreturnawaitmyAuthService.GetBearerTokenAsync(ct);};});
Domain Clients
ISamsaraClient exposes every Samsara API domain as a typed sub-client:
All list endpoints return IAsyncEnumerable<T>. The SDK fetches subsequent pages automatically:
// Stream all vehicles — pages fetched on demandawaitforeach(varvehicleinsamsara.Vehicles.ListAsync(ct)){Console.WriteLine($"{vehicle.Id}: {vehicle.Name}");}// Materialize to a list (System.Linq.Async)varallDrivers=awaitsamsara.Drivers.ListAsync(ct).ToListAsync(ct);// Take only the first page's worthvarfirstHundred=awaitsamsara.Tags.ListAsync(ct).Take(100).ToListAsync(ct);
// Stream live GPS + engine state for all vehiclesawaitforeach(varstatsinsamsara.Vehicles.ListStatsAsync("engineStates,gps",ct)){Console.WriteLine($"{stats.Name}: {stats.GpsOdometer}");}
The SDK throws strongly-typed exceptions. All exceptions inherit from SamsaraApiException which exposes StatusCode and RequestId for tracing.
Exception
HTTP Status
Notes
SamsaraBadRequestException
400
Invalid request payload or parameters
SamsaraAuthenticationException
401
Invalid or expired API token
SamsaraNotFoundException
404
Resource does not exist
SamsaraRateLimitException
429
Includes RetryAfter property
SamsaraServerException
500, 502, 503, 504
Transient server errors
try{varvehicle=awaitsamsara.Vehicles.GetAsync("bad-id",ct);}catch(SamsaraNotFoundExceptionex){Console.Error.WriteLine($"Not found — request ID: {ex.RequestId}");}catch(SamsaraRateLimitExceptionex)when(ex.RetryAfter.HasValue){awaitTask.Delay(ex.RetryAfter.Value,ct);// retry...}catch(SamsaraApiExceptionex){Console.Error.WriteLine($"API error {(int)ex.StatusCode}: {ex.Message}");}
Resilience
The SDK uses Microsoft.Extensions.Http.Resilience to automatically retry transient failures (5xx errors and network timeouts) with exponential backoff and jitter. No additional configuration is required for standard use.
builder.Services.AddSamsaraClient(options =>{options.ApiToken="samsara_api_...";options.RetryCount=5;// Default: 3. Set 0 to disable retries entirely.options.Timeout=TimeSpan.FromSeconds(60);});