Trackberry 0.1.0
dotnet add package Trackberry --version 0.1.0
NuGet\Install-Package Trackberry -Version 0.1.0
<PackageReference Include="Trackberry" Version="0.1.0" />
<PackageVersion Include="Trackberry" Version="0.1.0" />
<PackageReference Include="Trackberry" />
paket add Trackberry --version 0.1.0
#r "nuget: Trackberry, 0.1.0"
#:package Trackberry@0.1.0
#addin nuget:?package=Trackberry&version=0.1.0
#tool nuget:?package=Trackberry&version=0.1.0
Trackberry .NET SDK
The official .NET client for the Trackberry API: shipments, tracking, documents, packing lists, free time and ERP exports, with retries, idempotency keys, typed errors, pagination and webhook verification built in.
The client is generated from the API's OpenAPI document (openapi/openapi.json) with openapi-generator, and a thin hand-written layer on top sets the token, pins the API version, retries, and turns errors into exceptions. Method names are the operation names of the API reference: list_shipments is ListShipmentsAsync, record_erp_export is RecordErpExportAsync.
Install
dotnet add package Trackberry
Requires .NET 10 or later.
Quick start
using Trackberry;
using Trackberry.Model;
using var trackberry = new TrackberryClient("tb_..."); // or new TrackberryClient() to read TRACKBERRY_API_TOKEN
// Every shipment ready for the ERP or changed since its last export, page after page.
await foreach (var shipment in trackberry.ListAllAsync((after, ct) => trackberry.Shipments.ListShipmentsAsync(
erpStatus: new List<string> { "ready", "changed_since_export" },
updatedAfter: "2026-12-01T00:00:00Z",
limit: 100,
startingAfter: after, cancellationToken: ct)))
{
// The shipment as the ERP should import it.
var consignment = (await trackberry.Shipments.GetErpConsignmentAsync(shipment.Id)).Ok()!;
foreach (var row in consignment.Lines)
{
if (row.ErpConsignmentLine is { } line) { /* one packing line */ }
else if (row.ErpConsignmentGroup is { } group) { /* lines grouped together */ }
}
// ... import it ...
// Say which figures were imported: a later change makes the shipment come back as changed_since_export.
await trackberry.ShipmentActions.RecordErpExportAsync(shipment.Id, new RecordErpExportRequest(consignment.FiguresVersion));
}
The client has one property per section of the API reference: Shipments, ShipmentActions, Documents, Companies, AlertsAndChecks, FreeTime, PackingLines, Webhooks and so on. Each method returns the generated response; read the object with .Ok() (or .Created() for an answer that is a 201). Optional arguments are named and can be left out. Create one TrackberryClient and reuse it: it is thread-safe.
examples/ErpPolling is the loop above as a program.
Options
using var trackberry = new TrackberryClient(new TrackberryOptions
{
ApiToken = "tb_...", // default: TRACKBERRY_API_TOKEN
ApiVersion = "2026-10-01", // default: TrackberryClient.ApiVersion; null sends none
MaxRetries = 3, // default 3; 0 turns retries off
MaxRetryDelay = TimeSpan.FromSeconds(30),
Timeout = TimeSpan.FromSeconds(100), // per try
BaseUrl = new Uri("https://trackberry.com/api/v1"),
});
API version
Every request carries Trackberry-Version: by default TrackberryClient.ApiVersion, the version this release was generated from. Answers keep the shape the SDK was built for even after your organization's pin moves forward in settings. Set ApiVersion to send another, or to null to get the organization's pinned version. A generated method's trackberryVersion: argument overrides it for one call. The API version a release pins is in its release notes.
Errors
An answer outside 2xx throws a TrackberryException, after any retries. It carries StatusCode, Type, Code, Message, Param, RequestId (the X-Request-Id to quote to support), RetryAfter, ResponseBody and Headers. Branch on Code, show Message to people. Codes the SDK does not know yet arrive as they are.
| Exception | When |
|---|---|
AuthenticationException |
401: missing, malformed, revoked or expired token |
PermissionException |
403: a read token writing (insufficient_scope), billing |
NotFoundException |
404: no such object in the token's organization |
InvalidRequestException |
400, 409: the request cannot be done as sent; Param names the culprit |
IdempotencyException |
an InvalidRequestException about the Idempotency-Key (see below) |
RateLimitException |
429 once the retries are spent; wait RetryAfter |
TrackberryException |
anything else, a 5xx included |
try
{
await trackberry.ShipmentActions.RecordErpExportAsync(id, new RecordErpExportRequest(figuresVersion));
}
catch (InvalidRequestException e) when (e.Code == "unknown_figures_version")
{
// The figures changed while importing: import again on the next poll.
}
catch (NotFoundException e)
{
Console.WriteLine($"{e.Message} (request {e.RequestId})");
}
A network failure after the retries surfaces as HttpRequestException, a try that took longer than Timeout (the whole answer, body included) as TimeoutException.
Retries and idempotency
The client retries on 429, 502, 503, 504, a connection failure, a timed-out try, and a 409 idempotency_key_in_progress (the first request with that key is still running). It waits as long as Retry-After says when the answer has it, and otherwise backs off exponentially with full jitter (a random wait up to 0.5 s, 1 s, then 2 s, capped at MaxRetryDelay). Three retries by default. A Retry-After longer than MaxRetryDelay is not waited for: the exception is thrown with RetryAfter set.
A GET is always retried. A write is retried only when it carries an Idempotency-Key, which makes the retry safe: the API answers a repeat with the first answer instead of doing the write twice. So the client gives every write a random UUID key, the same one for all its retries, unless you pass your own:
// Your own key: the same import retried tomorrow is still recorded once.
await trackberry.ShipmentActions.RecordErpExportAsync(id, new RecordErpExportRequest(figuresVersion),
idempotencyKey: $"export-{id}-{figuresVersion}");
A replayed answer says so:
var response = await trackberry.ShipmentActions.RecordErpExportAsync(id, request);
if (response.IsIdempotentReplay())
Console.WriteLine($"Already done by request {response.OriginalRequestId()}");
Three operations handle the key their own way (shared by the organization's tokens, no Idempotent-Replayed header) and get no automatic key: TrackShipmentAsync (the key is a required argument), UploadDocumentAsync and SimulateShipmentEventAsync. Two more keep the key on the delivery they make, for 30 days, and send no Idempotent-Replayed either: SendWebhookTestEventAsync and RedeliverWebhookDeliveryAsync. They do get an automatic key, which only makes their own retries safe; IsIdempotentReplay() is always false on these five. Pass a key to UploadDocumentAsync (your own line id, say) to have it retried safely; without one it is sent once. A key reused with a different request throws an IdempotencyException with code idempotency_key_reused; an answer too large to keep throws one with code idempotency_response_too_large and the object's URL in Location.
Pagination
ListAllAsync walks a paged list: it passes the last item's id as startingAfter while has_more is true. Give it the call for one page and pass the cursor and the cancellation token through, so cancelling stops a page in flight too:
await foreach (var company in trackberry.ListAllAsync((after, ct) => trackberry.Companies.ListCompaniesAsync(q: "fruit", startingAfter: after, cancellationToken: ct)))
Console.WriteLine(company.Name);
It works with every operation that takes starting_after: shipments, pending shipments, messages, customer links, import reports, companies, alerts, checks, warehouses, closures, labels, automation runs, carrier free times, free time rules and tariffs, held emails, products, purchase orders, expected shipments and webhook deliveries. Stop early with break; only the pages you read are fetched.
Webhooks
Verify a delivery before acting on it, with the raw body exactly as received:
using Trackberry.Webhooks;
app.MapPost("/trackberry/webhooks", async (HttpRequest request) =>
{
using var reader = new StreamReader(request.Body);
var body = await reader.ReadToEndAsync();
WebhookEvent evt;
try
{
evt = Webhook.Verify(body, request.Headers.ToDictionary(h => h.Key, h => h.Value.ToString()), secret: "whsec_...");
}
catch (WebhookVerificationException)
{
return Results.BadRequest();
}
if (evt.Test == true)
return Results.Ok(); // A test delivery from settings: its data is made up, do not act on it.
switch (evt.Data)
{
case Trackberry.Model.ShipmentErpReadyRequest ready:
Console.WriteLine($"{ready.Data.Object.Id} is ready, figures {ready.Data.Erp.FiguresVersion}");
break;
}
return Results.Ok();
});
Webhook.Verify checks the Standard Webhooks signature (webhook-id, webhook-timestamp, webhook-signature; HMAC-SHA256 keyed with the secret after whsec_, compared in constant time) and refuses a timestamp more than 5 minutes from now (tolerance: changes it). It returns the event: Id (use it to drop duplicate deliveries), Type, CreatedAt, ApiVersion, Livemode, Test (true for a test delivery sent from settings, which you should acknowledge and not act on), Json, and Data, the generated model for the event's type (shipment.erp_ready is ShipmentErpReadyRequest). A webhook speaks the API version your organization is pinned to, not the SDK's: when that shape cannot be read as the SDK's model, Data is null and Json still has the whole event. Webhook.Sign makes a valid signature for your own tests.
Sandbox
if (await trackberry.IsSandboxAsync())
Console.WriteLine("This token belongs to a sandbox organization.");
IsSandboxAsync reads sandbox from get_organization once and remembers it. In a sandbox, trackberry.ErpSandbox.SimulateShipmentEventAsync makes things happen to a shipment (a new ETA, a corrected packing list) so you can see what your integration does; webhook events from a sandbox have Livemode false and come with a Trackberry-Sandbox: true header.
Development
openapi/openapi.json the spec snapshot the client is generated from
openapi/SOURCE the Trackberry commit it was taken from
generator/csharp.yaml openapi-generator options
generator/pom.xml the pinned openapi-generator version (Dependabot bumps it)
bin/regenerate the only way src/Trackberry/Generated changes
src/Trackberry/ Generated/ (never edited by hand) and the hand-written layer
tests/Trackberry.Tests unit tests (a fake HTTP handler, no network) and the Prism smoke tests
examples/ small programs that compile in CI
prism/ the pinned Prism mock server
bin/regenerate # needs Java 11+ or Docker
dotnet test --filter 'Category!=Smoke'
# The smoke tests, against a mock of the spec that answers with its examples:
npm ci --prefix prism
prism/node_modules/.bin/prism mock --port 4010 openapi/openapi.json &
TRACKBERRY_BASE_URL=http://127.0.0.1:4010 dotnet test --filter Category=Smoke
Never edit src/Trackberry/Generated by hand: CI regenerates it and fails on any difference. A spec change arrives as a pull request that updates openapi/ and runs bin/regenerate.
Releasing
Versions follow semantic versioning, tagged vMAJOR.MINOR.PATCH (v0.1.0, or v0.2.0-rc.1 for a pre-release); the package version is the tag without its v. Below 1.0, a minor version adds or changes generated code and a patch version only fixes. From 1.0, a major version is a breaking change or a new pinned Trackberry-Version, a minor version adds operations or fields, and a patch version fixes. The API's own date version stays in Trackberry-Version.
Publishing a GitHub release with such a tag runs .github/workflows/release.yml, which builds, tests, packs and pushes to nuget.org. It refuses a tag that is not semver or whose commit is not on main. Before tagging, give the version's CHANGELOG section its release date. The <Version> in src/Trackberry/Trackberry.csproj only names local builds; the workflow overrides it with the tag.
gh release create v0.1.0 --repo Trackberry/trackberry-dotnet --target main --title v0.1.0 --notes-file <notes>
The workflow uses NuGet trusted publishing: no API key is stored, the workflow exchanges its GitHub OIDC token for a short-lived key with the NuGet/login action. Before the first release, the owner sets up:
- On nuget.org, signed in as the
trackberryaccount: a trusted publishing policy for repository ownerTrackberry, repositorytrackberry-dotnet, workflow filerelease.yml, environmentnuget. - On GitHub, in this repository's settings: an environment named
nugetwhose deployment branches and tags are "Selected", with a tag rulev*(the release job runs on the tag's ref, somainalone would block it), and required reviewers if wanted. It holds no secret. The workflow file that runs is the one in the tagged commit, so the main check guards against mistakes, not against someone with push access: restrict who can createv*tags with a tag ruleset (admins only) and/or require reviewers on the environment. - Optional: ask nuget.org support to reserve the
Trackberry.prefix so the package shows as verified.
Until the policy exists, the release workflow fails at the NuGet login step.
Licence
MIT, see LICENSE.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Hosting (>= 11.0.0)
- Microsoft.Extensions.Http (>= 11.0.0)
- Microsoft.Extensions.Http.Polly (>= 11.0.0)
- Microsoft.Net.Http.Headers (>= 10.0.15)
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 |
|---|---|---|
| 0.1.0 | 0 | 12/5/2026 |