Official .NET SDK for the Sirv REST API.
- Supports .NET 6, 7, 8, 9, 10 and .NET Standard 2.0/2.1
- Full async/await support
- Automatic token management with refresh
- IAsyncEnumerable for efficient pagination
- Retry logic with exponential backoff
- All 40+ API endpoints implemented
- Comprehensive XML documentation
Install-Package Sirv.RestApi
dotnet add package Sirv.RestApi
<PackageReference Include="Sirv.RestApi" Version="1.0.0" />using Sirv.RestApi;
using Sirv.RestApi.Models;
// Create client
var client = new SirvClient(new SirvClientConfig
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret"
});
// Connect (optional - auto-connects on first request)
await client.ConnectAsync();
// Get account info
var account = await client.GetAccountInfoAsync();
Console.WriteLine($"CDN URL: {account.CdnUrl}");
// Upload a file
await client.UploadFileFromPathAsync("/images/photo.jpg", "./local-photo.jpg");
// Search files
var results = await client.SearchFilesAsync(new SearchParams { Query = "product" });
foreach (var file in results.Hits)
{
Console.WriteLine(file.Filename);
}var client = new SirvClient(new SirvClientConfig
{
// Required
ClientId = "your-client-id",
ClientSecret = "your-client-secret",
// Optional
BaseUrl = "https://api.sirv.com", // API base URL
AutoRefreshToken = true, // Auto-refresh token before expiry
TokenRefreshBuffer = 60, // Seconds before expiry to refresh
Timeout = 30000, // Request timeout in ms
MaxRetries = 3 // Retry failed requests
});| Option | Type | Default | Description |
|---|---|---|---|
ClientId |
string | - | Your Sirv API client ID (required) |
ClientSecret |
string | - | Your Sirv API client secret (required) |
BaseUrl |
string | https://api.sirv.com | API base URL |
AutoRefreshToken |
bool | true | Automatically refresh tokens |
TokenRefreshBuffer |
int | 60 | Seconds before expiry to refresh |
Timeout |
int | 30000 | Request timeout in milliseconds |
MaxRetries |
int | 3 | Max retries for failed requests |
You can customize the token expiry time (5 to 604,800 seconds / 7 days):
// Token valid for 1 hour
await client.ConnectAsync(3600);
// Token valid for 7 days
await client.ConnectAsync(604800);Use IAsyncEnumerable for efficient iteration over large result sets:
// Iterate through all files in a folder
await foreach (var file in client.IterateFolderContentsAsync("/images"))
{
Console.WriteLine(file.Filename);
}
// Iterate through search results
await foreach (var file in client.IterateSearchResultsAsync(new SearchParams { Query = "product" }))
{
Console.WriteLine(file.Filename);
}ConnectAsync()- Obtain bearer tokenIsConnected()- Check connection statusGetAccessToken()- Get current token
GetAccountInfoAsync()- Get account informationUpdateAccountAsync()- Update account settingsGetAccountLimitsAsync()- Get API rate limitsGetStorageInfoAsync()- Get storage usageGetAccountUsersAsync()- Get account usersGetBillingPlanAsync()- Get billing planSearchEventsAsync()- Search account eventsMarkEventsSeenAsync()- Mark events as seen
GetUserInfoAsync()- Get user information
GetFileInfoAsync()- Get file informationReadFolderContentsAsync()- Read folder contentsIterateFolderContentsAsync()- Async iteration over folderGetFolderOptionsAsync()- Get folder optionsSetFolderOptionsAsync()- Set folder optionsSearchFilesAsync()- Search filesScrollSearchAsync()- Continue search paginationIterateSearchResultsAsync()- Async iteration over searchDownloadFileAsync()- Download file as bytesDownloadFileToAsync()- Download file to local path
UploadFileAsync()- Upload from byte array or streamUploadFileFromPathAsync()- Upload from local pathCreateFolderAsync()- Create folderDeleteFileAsync()- Delete fileBatchDeleteAsync()- Delete multiple filesGetBatchDeleteStatusAsync()- Get batch delete statusCopyFileAsync()- Copy fileRenameFileAsync()- Rename/move fileFetchUrlAsync()- Fetch from URLBatchZipAsync()- Create ZIP archiveGetZipStatusAsync()- Get ZIP job status
GetFileMetaAsync()/SetFileMetaAsync()- File metadataGetFileTitleAsync()/SetFileTitleAsync()- File titleGetFileDescriptionAsync()/SetFileDescriptionAsync()- File descriptionGetFileTagsAsync()/AddFileTagsAsync()/RemoveFileTagsAsync()- File tagsGetProductMetaAsync()/SetProductMetaAsync()- Product metadataGetApprovalFlagAsync()/SetApprovalFlagAsync()- Approval flag
GenerateJwtAsync()- Generate protected URL
Spin2VideoAsync()- Convert spin to videoVideo2SpinAsync()- Convert video to spinExportSpinToAmazonAsync()- Export to AmazonExportSpinToWalmartAsync()- Export to WalmartExportSpinToHomeDepotAsync()- Export to Home DepotExportSpinToLowesAsync()- Export to Lowe'sExportSpinToGraingerAsync()- Export to Grainger
GetPointsOfInterestAsync()- Get POIsSetPointOfInterestAsync()- Set POIDeletePointOfInterestAsync()- Delete POI
GetHttpStatsAsync()- HTTP transfer statisticsGetSpinViewsStatsAsync()- Spin view statisticsGetStorageStatsAsync()- Storage statistics
using Sirv.RestApi.Exceptions;
try
{
await client.UploadFileFromPathAsync("/images/photo.jpg", "./photo.jpg");
}
catch (SirvApiException ex)
{
Console.WriteLine($"API Error: {ex.Message}");
Console.WriteLine($"Status: {ex.StatusCode}");
Console.WriteLine($"Code: {ex.ErrorCode}");
}- Log in to your Sirv account
- Go to Settings > API
- Create a new API client
- Copy your Client ID and Client Secret
MIT License - see LICENSE for details.