Skip to content

shopsavvy/sdk-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShopSavvy C# SDK

Official C# SDK for the ShopSavvy Data API - Access product data, pricing information, and price history across thousands of retailers and millions of products.

Installation

NuGet Package Manager

Install-Package ShopSavvy.DataApi

.NET CLI

dotnet add package ShopSavvy.DataApi

PackageReference

<PackageReference Include="ShopSavvy.DataApi" Version="1.0.0" />

Quick Start

using System;
using System.Threading.Tasks;
using ShopSavvy.DataApi;

class Program
{
    static async Task Main(string[] args)
    {
        // Create a new client
        using var client = new ShopSavvyDataApiClient("ss_live_your_api_key_here");
        
        // Look up a product by barcode
        var product = await client.GetProductDetailsAsync("012345678901");
        Console.WriteLine($"Product: {product.Data.Name}");
        
        if (!string.IsNullOrEmpty(product.Data.Brand))
        {
            Console.WriteLine($"Brand: {product.Data.Brand}");
        }
        
        // Get current offers
        var offers = await client.GetCurrentOffersAsync("012345678901");
        Console.WriteLine($"Found {offers.Data.Length} offers:");
        
        foreach (var offer in offers.Data)
        {
            Console.WriteLine($"  {offer.Retailer}: ${offer.Price:F2} ({offer.Availability})");
        }
    }
}

Configuration

You can customize the client behavior:

var config = new ShopSavvyConfig
{
    ApiKey = "ss_live_your_api_key_here",
    BaseUrl = "https://api.shopsavvy.com/v1",
    Timeout = TimeSpan.FromSeconds(60)
};

using var client = new ShopSavvyDataApiClient(config);

API Methods

Product Details

// Single product
var product = await client.GetProductDetailsAsync("012345678901");

// Multiple products
var products = await client.GetProductDetailsBatchAsync(new[] { "012345678901", "B08N5WRWNW" });

// CSV format
var productCsv = await client.GetProductDetailsAsync("012345678901", "csv");

Current Offers

// All retailers
var offers = await client.GetCurrentOffersAsync("012345678901");

// Specific retailer
var amazonOffers = await client.GetCurrentOffersAsync("012345678901", "amazon");

// Multiple products
var offersBatch = await client.GetCurrentOffersBatchAsync(new[] { "012345678901", "B08N5WRWNW" });

Price History

var history = await client.GetPriceHistoryAsync("012345678901", "2024-01-01", "2024-01-31");

// With specific retailer
var amazonHistory = await client.GetPriceHistoryAsync("012345678901", "2024-01-01", "2024-01-31", "amazon");

Product Monitoring

// Schedule monitoring
var result = await client.ScheduleProductMonitoringAsync("012345678901", "daily");

// Schedule multiple products
var results = await client.ScheduleProductMonitoringBatchAsync(
    new[] { "012345678901", "B08N5WRWNW" }, 
    "daily"
);

// Get scheduled products
var scheduled = await client.GetScheduledProductsAsync();

// Remove from schedule
var removed = await client.RemoveProductFromScheduleAsync("012345678901");

// Remove multiple from schedule
var removedBatch = await client.RemoveProductsFromScheduleAsync(new[] { "012345678901", "B08N5WRWNW" });

Usage Information

var usage = await client.GetUsageAsync();
Console.WriteLine($"Credits remaining: {usage.Data.CreditsRemaining}");

Error Handling

The SDK provides specific exception types for different scenarios:

try
{
    var product = await client.GetProductDetailsAsync("invalid-id");
}
catch (ShopSavvyAuthenticationException ex)
{
    Console.WriteLine("Invalid API key");
}
catch (ShopSavvyNotFoundException ex)
{
    Console.WriteLine("Product not found");
}
catch (ShopSavvyValidationException ex)
{
    Console.WriteLine("Invalid request parameters");
}
catch (ShopSavvyRateLimitException ex)
{
    Console.WriteLine("Rate limit exceeded");
}
catch (ShopSavvyNetworkException ex)
{
    Console.WriteLine($"Network error: {ex.Message}");
}
catch (ShopSavvyTimeoutException ex)
{
    Console.WriteLine($"Request timeout: {ex.Message}");
}
catch (ShopSavvyApiException ex)
{
    Console.WriteLine($"API error: {ex.Message}");
}

Response Structure

All API responses follow the same structure:

public class ApiResponse<T>
{
    public bool Success { get; set; }
    public T Data { get; set; }
    public string? Message { get; set; }
    public int? CreditsUsed { get; set; }
    public int? CreditsRemaining { get; set; }
}

Async/Await Support

All methods are fully async and support cancellation tokens:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));

try
{
    var product = await client.GetProductDetailsAsync("012345678901");
}
catch (OperationCanceledException)
{
    Console.WriteLine("Request was cancelled");
}

Dependency Injection

The client can be easily used with dependency injection:

services.AddSingleton(new ShopSavvyConfig
{
    ApiKey = configuration["ShopSavvy:ApiKey"],
    Timeout = TimeSpan.FromSeconds(60)
});

services.AddScoped<ShopSavvyDataApiClient>();

Requirements

Supported Platforms

  • .NET Core 2.0+
  • .NET Framework 4.6.1+
  • .NET 5.0+
  • Xamarin.iOS
  • Xamarin.Android
  • Unity 2018.1+

License

MIT License - see LICENSE file for details.

Links

About

Official C# SDK for ShopSavvy Data API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages