Grula.PricingIntelligencePlatform.Sdk 1.0.3

dotnet add package Grula.PricingIntelligencePlatform.Sdk --version 1.0.3
                    
NuGet\Install-Package Grula.PricingIntelligencePlatform.Sdk -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Grula.PricingIntelligencePlatform.Sdk" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Grula.PricingIntelligencePlatform.Sdk" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Grula.PricingIntelligencePlatform.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Grula.PricingIntelligencePlatform.Sdk --version 1.0.3
                    
#r "nuget: Grula.PricingIntelligencePlatform.Sdk, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Grula.PricingIntelligencePlatform.Sdk@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Grula.PricingIntelligencePlatform.Sdk&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Grula.PricingIntelligencePlatform.Sdk&version=1.0.3
                    
Install as a Cake Tool

Grula Pricing Intelligence Platform SDK for .NET

NuGet Build Status

A .NET SDK for the Grula Pricing Intelligence Platform API, providing easy access to pricing policies, drivers, and price calculations.

Features

  • Price Calculations: Get prices based on price drivers and currency
  • Strongly Typed: Generated from OpenAPI specification for type safety
  • Async/Await Support: Full async support for all operations
  • Authentication: Built-in support for Bearer token authentication

Installation

Install the package via NuGet Package Manager:

dotnet add package Grula.PricingIntelligencePlatform.Sdk

Or via Package Manager Console:

Install-Package Grula.PricingIntelligencePlatform.Sdk

Quick Start

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Net.Http.Headers;
using Grula.PricingIntelligencePlatform.Sdk;

// In Program.cs or Startup.cs
var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHttpClient("GrulaApi", client =>
{
    client.BaseAddress = new Uri("https://api.grula.net");
    client.DefaultRequestHeaders.Authorization = 
        new AuthenticationHeaderValue("Bearer", builder.Configuration["GrulaApi:ApiKey"]);
})
.AddTypedClient((httpClient, serviceProvider) =>
{
    var baseUrl = "https://api.grula.net"; // or get from configuration
    return new GrulaApiClient(baseUrl, httpClient);
});

var host = builder.Build();

Using the Client in a Service

public class PricingService
{
    private readonly GrulaApiClient _grulaClient;

    public PricingService(GrulaApiClient grulaClient)
    {
        _grulaClient = grulaClient;
    }

    public async Task<decimal> GetProductPriceAsync(string product, string region, string currency = "USD")
    {
        var priceQuery = new GetPriceByPriceDriversQuery
        {
            EnvironmentId = Guid.Parse("your-environment-id"),
            CurrencyThreeLetterCode = currency,
            PricingDate = DateTime.UtcNow,
            PriceDrivers = new[]
            {
                new PriceDriver { Name = "Product", Value = product },
                new PriceDriver { Name = "Region", Value = region }
            }
        };

        var price = await _grulaClient.GetPriceByPriceDriversAsync(priceQuery);
        return (decimal)price.Amount.Amount;
    }

    public async Task<List<decimal>> GetMultiplePricesAsync(List<(string product, string region, string currency)> requests)
    {
        var pricesQuery = new GetPricesByPriceDriversQuery
        {
            EnvironmentId = Guid.Parse("your-environment-id"),
            PriceRequests = requests.Select(r => new PriceRequest
            {
                CurrencyThreeLetterCode = r.currency,
                PricingDate = DateTime.UtcNow,
                PriceDrivers = new[]
                {
                    new PriceDriver { Name = "Product", Value = r.product },
                    new PriceDriver { Name = "Region", Value = r.region }
                }
            }).ToArray()
        };

        var prices = await _grulaClient.GetPricesByPriceDriversAsync(pricesQuery);
        return prices.Select(p => (decimal)p.Amount.Amount).ToList();
    }
}

Get Price by Drivers

var priceQuery = new GetPriceByPriceDriversQuery
{
    EnvironmentId = Guid.Parse("your-environment-id"),
    CurrencyThreeLetterCode = "USD",
    PricingDate = DateTime.UtcNow,
    PriceDrivers = new[]
    {
        new PriceDriver { Name = "Product", Value = "Premium" },
        new PriceDriver { Name = "Region", Value = "US-East" }
    }
};

var price = await client.GetPriceByPriceDriversAsync(priceQuery);
Console.WriteLine($"Price: {price.Amount.Amount} {price.Amount.CurrencyThreeLetterCode}");

Get Multiple Prices (Batch Request)

var pricesQuery = new GetPricesByPriceDriversQuery
{
    EnvironmentId = Guid.Parse("your-environment-id"),
    PriceRequests = new[]
    {
        new PriceRequest
        {
            CurrencyThreeLetterCode = "USD",
            PricingDate = DateTime.UtcNow,
            PriceDrivers = new[]
            {
                new PriceDriver { Name = "Product", Value = "Basic" },
                new PriceDriver { Name = "Region", Value = "US-West" }
            }
        },
        new PriceRequest
        {
            CurrencyThreeLetterCode = "EUR",
            PricingDate = DateTime.UtcNow,
            PriceDrivers = new[]
            {
                new PriceDriver { Name = "Product", Value = "Premium" },
                new PriceDriver { Name = "Region", Value = "EU-Central" }
            }
        }
    }
};

var prices = await client.GetPricesByPriceDriversAsync(pricesQuery);
foreach (var price in prices)
{
    Console.WriteLine($"Price: {price.Amount.Amount} {price.Amount.CurrencyThreeLetterCode}");
}

Basic Setup (Alternative)

using System.Net.Http.Headers;
using Grula.PricingIntelligencePlatform.Sdk;

var httpClient = new HttpClient
{
    BaseAddress = new Uri("https://api.grula.net")
};

httpClient.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", "your-api-key-here");

var client = new GrulaApiClient("https://api.grula.net", httpClient);

Configuration

HttpClient Configuration

You can configure the HttpClient with additional settings:

var httpClient = new HttpClient
{
    BaseAddress = new Uri("https://api.grula.net"),
    Timeout = TimeSpan.FromSeconds(30)
};

httpClient.DefaultRequestHeaders.Authorization = 
    new AuthenticationHeaderValue("Bearer", "your-api-key-here");

var client = new GrulaApiClient("https://api.grula.net", httpClient);

Dependency Injection

Register the client in your DI container:

services.AddHttpClient("GrulaApi", client =>
{
    client.BaseAddress = new Uri("https://api.grula.net");
    client.DefaultRequestHeaders.Authorization = 
        new AuthenticationHeaderValue("Bearer", configuration["GrulaApi:ApiKey"]);
})
.AddTypedClient((httpClient, serviceProvider) =>
{
    var baseUrl = "https://api.grula.net"; // or get from configuration
    return new GrulaApiClient(baseUrl, httpClient);
});

Logging

The SDK supports logging through the HttpClient:

services.AddHttpClient("GrulaApi", client =>
{
    client.BaseAddress = new Uri("https://api.grula.net");
    client.DefaultRequestHeaders.Authorization = 
        new AuthenticationHeaderValue("Bearer", configuration["GrulaApi:ApiKey"]);
})
.AddTypedClient((httpClient, serviceProvider) =>
{
    var baseUrl = "https://api.grula.net";
    return new GrulaApiClient(baseUrl, httpClient);
})
.AddLogger(); // Add logging to the HttpClient

Error Handling

The SDK throws exceptions for HTTP errors. Handle them appropriately:

try
{
    var price = await client.GetPriceByPriceDriversAsync(priceQuery);
}
catch (ApiException ex)
{
    Console.WriteLine($"API Error: {ex.StatusCode} - {ex.Message}");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"Network Error: {ex.Message}");
}

Troubleshooting

Common Issues

InvalidOperationException: Unable to resolve service for type 'System.String'

This error occurs when using the generic AddHttpClient<GrulaApiClient>() method. The generated GrulaApiClient requires both a baseUrl string and an HttpClient instance in its constructor.

Solution: Use the factory-based registration pattern shown in the examples above:

services.AddHttpClient("GrulaApi", client =>
{
    client.BaseAddress = new Uri("https://api.grula.net");
    client.DefaultRequestHeaders.Authorization = 
        new AuthenticationHeaderValue("Bearer", configuration["GrulaApi:ApiKey"]);
})
.AddTypedClient((httpClient, serviceProvider) =>
{
    var baseUrl = "https://api.grula.net";
    return new GrulaApiClient(baseUrl, httpClient);
});

API Reference

Price Calculations

  • GetPriceByPriceDriversAsync() - Get a single price
  • GetPricesByPriceDriversAsync() - Get multiple prices (max 100 requests)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For support and questions:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 777 9/14/2025
1.0.2 1,167 7/29/2025