Blacus.TropicAPIWrapper 10.0.1

dotnet add package Blacus.TropicAPIWrapper --version 10.0.1
                    
NuGet\Install-Package Blacus.TropicAPIWrapper -Version 10.0.1
                    
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="Blacus.TropicAPIWrapper" Version="10.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blacus.TropicAPIWrapper" Version="10.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Blacus.TropicAPIWrapper" />
                    
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 Blacus.TropicAPIWrapper --version 10.0.1
                    
#r "nuget: Blacus.TropicAPIWrapper, 10.0.1"
                    
#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 Blacus.TropicAPIWrapper@10.0.1
                    
#: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=Blacus.TropicAPIWrapper&version=10.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Blacus.TropicAPIWrapper&version=10.0.1
                    
Install as a Cake Tool

Blacus.TropicAPIWrapper

A modern .NET 10 client library for interacting with the Tropic API.

Features

  • Typed Models & Resources: Clean, strongly-typed wrappers for Contracts, Purchase Requests, Comments, and Suppliers using standard auto-properties.
  • Direct Resource Access: Idiomatic resource calls via client.Contracts, client.PurchaseRequests, client.Comments, client.Suppliers, and client.Webhooks.
  • Interface Abstraction & DI Support: Full ITropicClient and resource interfaces (IContractsResource, IPurchaseRequestsResource, etc.) with turnkey services.AddTropicClient() dependency injection extensions for ASP.NET Core.
  • Safe HttpClient Integration: Per-request headers and relative URI resolution ensure shared HttpClient instances (e.g. from IHttpClientFactory) are never mutated.
  • Automatic Rate Limit Handling: Built-in exponential backoff retry mechanism for HTTP 429 (TooManyRequests), handling both delta and date-based Retry-After headers.
  • Webhook Verification: Timing-safe HMAC-SHA256 verification of Tropic-Signature and Tropic-Timestamp headers with optional anti-replay timestamp tolerance.
  • Zero Third-Party Dependencies: Pure .NET 10 BCL implementation with no external runtime dependencies.

Target Framework

  • .NET 10.0 (net10.0)

Installation

Add the project reference or package to your .NET project:

dotnet add reference path/to/Blacus.TropicAPIWrapper.csproj

Quickstart

Dependency Injection (ASP.NET Core / Generic Host)

Register ITropicClient directly into your service collection in Program.cs:

using Microsoft.Extensions.DependencyInjection;

// Option 1: Bind from configuration section ("Tropic" in appsettings.json)
builder.Services.AddTropicClient();

// Option 2: Provide API key directly
builder.Services.AddTropicClient("your_tropic_api_key");

// Option 3: Full options configuration
builder.Services.AddTropicClient(options =>
{
    options.ApiKey = builder.Configuration["Tropic:ApiKey"]!;
    options.BaseUrl = "https://app.tropicapp.io";
});

When registered with AddTropicClient, you can inject ITropicClient, the concrete TropicClient, or any individual resource (e.g., IContractsResource, ISuppliersResource) directly into your services:

public class ProcurementService(IContractsResource contractsResource)
{
    public async Task<List<ContractModel>?> GetActiveContractsAsync()
    {
        return await contractsResource.GetAllAsync();
    }
}

Standalone Client Initialization

using Blacus.TropicAPIWrapper;

// Basic initialization
using var client = new TropicClient("your_tropic_api_key");

// Or with an existing shared HttpClient and custom base URL
using var customClient = new TropicClient(
    apiKey: "your_tropic_api_key",
    httpClient: sharedHttpClient,
    baseUrl: "https://app.tropicapp.io"
);

API Usage Examples

All asynchronous operations follow the standard .NET Task-based Asynchronous Pattern (TAP) using the *Async naming convention (GetAllAsync, GetPageAsync, GetAsync, CreateAsync, UpdateAsync, SearchAsync).

1. Contracts

using Blacus.TropicAPIWrapper.Models;

// List all contracts (auto-paginates all pages)
List<ContractModel>? contracts = await client.Contracts.GetAllAsync();

// Fetch a single page of contracts with pagination metadata
TropicPagedResponse<ContractModel>? page = await client.Contracts.GetPageAsync(page: 1, perPage: 50);

// Fetch a single contract by ID
ContractModel? contract = await client.Contracts.GetAsync("contract_12345");

// Create a new contract
var newContract = await client.Contracts.CreateAsync(new ContractRequest
{
    Name = "Cloud Infrastructure Annual Agreement",
    SupplierId = "supp_12345",
    Status = "active",
    TotalValue = 50000m,
    Currency = "USD",
    StartDate = DateTimeOffset.UtcNow,
    EndDate = DateTimeOffset.UtcNow.AddYears(1),
    AutoRenew = true
});

// Update an existing contract
var updatedContract = await client.Contracts.UpdateAsync("contract_12345", new ContractRequest
{
    Name = "Cloud Infrastructure Annual Agreement - Renewal",
    TotalValue = 55000m
});

2. Purchase Requests

using Blacus.TropicAPIWrapper.Models;

// List all purchase requests (auto-paginates across all pages)
List<PurchaseRequestModel>? requests = await client.PurchaseRequests.GetAllAsync();

// Fetch a single page of purchase requests with pagination metadata
TropicPagedResponse<PurchaseRequestModel>? page = await client.PurchaseRequests.GetPageAsync(page: 1, perPage: 50);

// Fetch a single purchase request by ID
PurchaseRequestModel? request = await client.PurchaseRequests.GetAsync("pr_12345");

// Update a purchase request
var updatedRequest = await client.PurchaseRequests.UpdateAsync("pr_12345", new PurchaseRequestUpdateRequest
{
    Status = "approved",
    Amount = 12000m,
    Currency = "USD",
    Description = "Approved marketing software licenses"
});

3. Comments

using Blacus.TropicAPIWrapper.Models;

// Get comments for a purchase request
List<CommentModel>? comments = await client.Comments.GetAllAsync("pr_12345");

// Add a comment to a purchase request
var comment = await client.Comments.CreateAsync("pr_12345", new CommentCreateRequest
{
    Body = "Reviewed and approved by procurement team."
});

4. Suppliers

using Blacus.TropicAPIWrapper.Models;

// Search suppliers by keyword
List<SupplierModel>? searchResults = await client.Suppliers.SearchAsync("Acme");

// Fetch supplier by ID
SupplierModel? supplier = await client.Suppliers.GetAsync("supp_12345");

// Create a supplier
var newSupplier = await client.Suppliers.CreateAsync(new SupplierRequest
{
    Name = "Acme Cloud Services",
    Website = "https://acme.example.com",
    ContactName = "Jane Doe",
    ContactEmail = "jane.doe@acme.example.com",
    ContactPhone = "+1-555-0100"
});

// Update a supplier
var updatedSupplier = await client.Suppliers.UpdateAsync("supp_12345", new SupplierRequest
{
    Name = "Acme Cloud Services Inc."
});

5. Webhook Verification & Payloads

Tropic sends incoming webhooks with Tropic-Timestamp and Tropic-Signature HTTP headers. You can verify signatures and optionally enforce a timestamp tolerance to guard against replay attacks:

using System.Text.Json;
using Blacus.TropicAPIWrapper.Models;

// Verify webhook signature with a 5-minute replay tolerance window
bool isValid = client.Webhooks.Verify(
    webhookSecret: "your_webhook_signing_secret",
    tropicTimestampHeader: request.Headers["Tropic-Timestamp"],
    rawRequestBody: rawPayloadString,
    tropicSignatureHeader: request.Headers["Tropic-Signature"],
    tolerance: TimeSpan.FromMinutes(5)
);

if (!isValid)
{
    return Results.Unauthorized();
}

// Deserialize the webhook payload
var payload = JsonSerializer.Deserialize<WebhookEventPayload<PurchaseRequestModel>>(rawPayloadString);
Console.WriteLine($"Received event {payload?.EventType} for ID {payload?.Data?.Id}");

Error Handling

When the Tropic API returns an unsuccessful status code, a TropicApiException is thrown containing the HTTP status code and response body:

using Blacus.TropicAPIWrapper;

try
{
    var contract = await client.Contracts.UpdateAsync("invalid_id", new ContractRequest());
}
catch (TropicApiException ex)
{
    Console.WriteLine($"Status: {ex.StatusCode} ({(int)ex.StatusCode})");
    Console.WriteLine($"Message: {ex.Message}");
    Console.WriteLine($"Response Body: {ex.ResponseBody}");
}

Building and Packaging

To compile the library locally using the .NET SDK:

dotnet build src/Blacus.TropicAPIWrapper/Blacus.TropicAPIWrapper.csproj

To pack the NuGet package and symbols:

dotnet pack src/Blacus.TropicAPIWrapper/Blacus.TropicAPIWrapper.csproj -c Release

Publishing to NuGet

Automated publishing is configured via GitHub Actions in .github/workflows/publish.yml.

Prerequisites

Add your NuGet API key as a repository secret:

  1. Navigate to Settings > Secrets and variables > Actions in your GitHub repository.
  2. Add a new repository secret named NUGET_API_KEY with your API key from nuget.org.

Releasing via Git Tag

Pushing a version tag automatically builds, packs, publishes the package to NuGet.org, and creates a GitHub Release:

git tag v1.0.0
git push origin v1.0.0

Manual Trigger

You can also trigger a release manually from GitHub Actions:

  1. Go to Actions > Publish to NuGet.
  2. Click Run workflow, optionally specifying a version override and whether to run in dry_run mode.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
10.0.1 90 11/2/2026
1.0.0 86 11/2/2026