Skip to content

sirv/sirv-rest-api-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sirv.RestApi

Official .NET SDK for the Sirv REST API.

NuGet License: MIT

Features

  • 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

Installation

NuGet Package Manager

Install-Package Sirv.RestApi

.NET CLI

dotnet add package Sirv.RestApi

PackageReference

<PackageReference Include="Sirv.RestApi" Version="1.0.0" />

Quick Start

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);
}

Configuration

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

Custom Token Expiry

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);

Async Enumeration

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);
}

API Coverage

Authentication

  • ConnectAsync() - Obtain bearer token
  • IsConnected() - Check connection status
  • GetAccessToken() - Get current token

Account API

  • GetAccountInfoAsync() - Get account information
  • UpdateAccountAsync() - Update account settings
  • GetAccountLimitsAsync() - Get API rate limits
  • GetStorageInfoAsync() - Get storage usage
  • GetAccountUsersAsync() - Get account users
  • GetBillingPlanAsync() - Get billing plan
  • SearchEventsAsync() - Search account events
  • MarkEventsSeenAsync() - Mark events as seen

User API

  • GetUserInfoAsync() - Get user information

Files API - Reading

  • GetFileInfoAsync() - Get file information
  • ReadFolderContentsAsync() - Read folder contents
  • IterateFolderContentsAsync() - Async iteration over folder
  • GetFolderOptionsAsync() - Get folder options
  • SetFolderOptionsAsync() - Set folder options
  • SearchFilesAsync() - Search files
  • ScrollSearchAsync() - Continue search pagination
  • IterateSearchResultsAsync() - Async iteration over search
  • DownloadFileAsync() - Download file as bytes
  • DownloadFileToAsync() - Download file to local path

Files API - Writing

  • UploadFileAsync() - Upload from byte array or stream
  • UploadFileFromPathAsync() - Upload from local path
  • CreateFolderAsync() - Create folder
  • DeleteFileAsync() - Delete file
  • BatchDeleteAsync() - Delete multiple files
  • GetBatchDeleteStatusAsync() - Get batch delete status
  • CopyFileAsync() - Copy file
  • RenameFileAsync() - Rename/move file
  • FetchUrlAsync() - Fetch from URL
  • BatchZipAsync() - Create ZIP archive
  • GetZipStatusAsync() - Get ZIP job status

Metadata API

  • GetFileMetaAsync() / SetFileMetaAsync() - File metadata
  • GetFileTitleAsync() / SetFileTitleAsync() - File title
  • GetFileDescriptionAsync() / SetFileDescriptionAsync() - File description
  • GetFileTagsAsync() / AddFileTagsAsync() / RemoveFileTagsAsync() - File tags
  • GetProductMetaAsync() / SetProductMetaAsync() - Product metadata
  • GetApprovalFlagAsync() / SetApprovalFlagAsync() - Approval flag

JWT API

  • GenerateJwtAsync() - Generate protected URL

Spins/360 API

  • Spin2VideoAsync() - Convert spin to video
  • Video2SpinAsync() - Convert video to spin
  • ExportSpinToAmazonAsync() - Export to Amazon
  • ExportSpinToWalmartAsync() - Export to Walmart
  • ExportSpinToHomeDepotAsync() - Export to Home Depot
  • ExportSpinToLowesAsync() - Export to Lowe's
  • ExportSpinToGraingerAsync() - Export to Grainger

Points of Interest API

  • GetPointsOfInterestAsync() - Get POIs
  • SetPointOfInterestAsync() - Set POI
  • DeletePointOfInterestAsync() - Delete POI

Statistics API

  • GetHttpStatsAsync() - HTTP transfer statistics
  • GetSpinViewsStatsAsync() - Spin view statistics
  • GetStorageStatsAsync() - Storage statistics

Error Handling

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}");
}

Getting API Credentials

  1. Log in to your Sirv account
  2. Go to Settings > API
  3. Create a new API client
  4. Copy your Client ID and Client Secret

Documentation

License

MIT License - see LICENSE for details.

Support

About

Sirv REST API .Net SDK

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages