.Net SDK

SDK that works with the Spresso APIs.

Price Optimization SDK provides:

  • Authentication
  • Resilient API calls

SpressoHandler is the main entrypoint for the Spresso SDK. First, construct a new instance:

var spressoHandler = new SpressoHandler("myClientId", "mySecret");

Client ID and Client Secret are unique to your organization and can be found in our admin console

NOTE: SpressoHandler is reentrant and thread-safe. It is designed to be used as a singleton - instantiated once and reused to make multiple Spresso API requests throughout the life of the application.

1. Single Price Optimization Request

Get the optimized, AI-generated price for a single SKU + deviceId pairing.

var response = await spressoHandler.GetPriceAsync(
  new GetPriceRequest(
    deviceId: "device-123", 
    itemId: "abc", 
    defaultPrice: 9.99m, 
    userId: "u42", 
    overrideToDefaultPrice: false, 
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
  )
);

2. Batch Price Optimization Request

Get the optimized, AI-generated price for multiple SKUs in one request.

var batchResponse = spressoHandler.GetPricesAsync(
    new GetPricesRequest(new[]
    {
        new GetPriceRequest(
            deviceId: "device-123", 
            itemId: "abc", 
            defaultPrice: 19.99m, 
            userId: "u42",
            overrideToDefaultPrice: false
        ),
        new GetPriceRequest(
            deviceId: "device-123",
            itemId: "xyz", 
            defaultPrice: 11.99m,
            userId: "u42",
            overrideToDefaultPrice: false
        )
    }, userAgent: "google-bot"));

Explanation of each input:

  • deviceId: - string, required. The deviceId must be retrieved from the spressoDeviceId cookie created by our JS SDK and dropped in the browser of every user of your site.
  • itemId - string, required. Identifies an individual variant in your catalog. This must match the SKU you have provided us in our admin console.
  • defaultPrice - decimal. This value is used as a fallback in case of an error communicating with our API. If you do not provide a defaultPrice, you will get null back as a price from our SDK instead.
  • overrideToDefaultPrice - bool. This value is used in the situation that you want to force the Spresso API to return the defaultPrice for that SKU.
  • userId - string. A unique identifier for each user of your platform.
  • userAgent - string, required. The User Agent of the browser where the price will be displayed. Spresso's API uses this to detect bot traffic and automatically displays the catalog, i.e. the non-optimized, price for all SKUs requested by this device.

Example responses for single and batch price optimization requests:

  • IsSuccess - bool. API was hit successfully, no errors
  • Error - byte. Available values [None, AuthError, BadRequest, Timeout, Unknown]
  • PriceOptimization:
    • ItemId - string
    • DeviceId - string
    • UserId - string
    • Price - decimal
    • IsPriceOptimized - bool

3. Catalog Update Request

Overwrite existing catalog data (PUT semantics) with new information for up to 500 items at a time.

var batchResponse = spressoHandler.UpdateCatalogAsync(
    new CatalogUpdatesRequest(new[]
    {
        new CatalogUpdateRequest( 
            sku: "abc", 
            name: "the best product ever", 
            productId: "xyz-product", 
            category: "birds, bees, other",
            upc: "1234567890",
            brand: "best brand name here",
            cost: 12.34m,
            price: 56.78m,
            mapPrice: 49.99m,
            msrpPrice: 59.99m,
        ),
        new CatalogUpdateRequest(
            sku: "xyz", 
            name: "the SECOND best product ever", 
            productId: "foo-product", 
            category: "widgets",
            upc: "9876543210",
            brand: "SECOND best brand name here",
            cost: 9.87m,
            price: 43.21m,
            mapPrice: 39.99m,
            msrpPrice: 49.99m,
        )
    });

Explanation of each input:

  • sku - string, required. Identifies an individual variant in your catalog. This must match the SKU used above for price optimization requests.
  • name - string, required. Name of the variant.
  • productId - string. The SKU identifies the variant, this identifies the product. There is a Many -> One relationship between variants and products.
  • category - string. Useful if you want to break our reports by category in our console.
  • upc - string.
  • brand - string.
  • cost - decimal, required. The cost of the variant. This needs to be as accurate as possible and is an important input for our AI.
  • price - decimal, required. The current default (aka catalog) price of the variant.
  • mapPrice - decimal. Minimum Advertised Price.
  • msrpPrice - decimal. Maximum Suggested Retail Price.

Example response:

  • IsSuccess - bool. API was hit successfully, no errors
  • Error - byte. Available values [None, AuthError, BadRequest, Timeout, Unknown]

4. Price Verification Request

Confirm the prices that were generated by Spresso for a given device ID

var batchResponse = spressoHandler.VerifyPricesAsync(
    new PricesVerificationRequest(new[]
    {
        new PriceVerificationRequest( 
            itemId: "abc", 
            deviceId: "device-123", 
            price: 56.78m,
        ),
        new PriceVerificationRequest(
            itemId: "xyz", 
            deviceId: "device-123", 
            price: 12.34m,
        )
    });

Explanation of each input:

  • deviceId: - string. Device ID is optional in this request. If you provide the deviceId, our response will indicate whether the price was displayed to that device, if you do not we will only verify if the price was one of the possible prices our API might have displayed.
  • itemId - string, required. Identifies an individual variant in your catalog. This must match the SKU you have provided us in our admin console.
  • price - decimal, required. The price displayed to the user in the browser that needs to be verified as accurate.

Example responses for price verification requests:

  • IsSuccess - bool. API was hit successfully, no errors
  • Error - byte. Available values [None, AuthError, BadRequest, Timeout, Unknown]
  • PriceVerification:
    • ItemId - string
    • DeviceId - string
    • Price - decimal. The price provided to us in the input
    • CurrentValidPrice - decimal. The current valid Spresso price. Will only be returned if deviceId is provided in the input.
    • priceStatus - byte. Available values [Invalid, SpressoPrice, DevicePrice]

Invalid -> the price is not a valid price returned by Spresso.

SpressoPrice -> the price is one of the prices our AI might have returned.

DevicePrice -> the price is the exact price displayed to the device. Will only be returned if deviceId is provided in the input.

NOTE: The status SpressoPrice may be provided even if a deviceId is provided in the input. This scenario would occur if our model had originally allocated the given price to that device, but has subsequently reallocated a new price to the device. It is up to the user to decide whether to use the Price or CurrentValidPrice in this scenario.