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
<PackageReference Include="Grula.PricingIntelligencePlatform.Sdk" Version="1.0.3" />
<PackageVersion Include="Grula.PricingIntelligencePlatform.Sdk" Version="1.0.3" />
<PackageReference Include="Grula.PricingIntelligencePlatform.Sdk" />
paket add Grula.PricingIntelligencePlatform.Sdk --version 1.0.3
#r "nuget: Grula.PricingIntelligencePlatform.Sdk, 1.0.3"
#:package Grula.PricingIntelligencePlatform.Sdk@1.0.3
#addin nuget:?package=Grula.PricingIntelligencePlatform.Sdk&version=1.0.3
#tool nuget:?package=Grula.PricingIntelligencePlatform.Sdk&version=1.0.3
Grula Pricing Intelligence Platform SDK for .NET
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
Setup with Dependency Injection (Recommended)
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 priceGetPricesByPriceDriversAsync()
- Get multiple prices (max 100 requests)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and questions:
- Create an issue on GitHub
- Visit the API documentation
Product | Versions 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. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.