CropPath for developers

All guides

C# / .NET SDK

Available

A typed client of the HTTP API for .NET systems.

CropPath.Sdk is a typed C# client of the whole HTTP API, for packing houses and ERP integrations. Every operation has a synchronous and an ...Async method, grouped as in the reference (client.Lots, client.Packing, client.Shipping, ...); each returns the decoded model or throws a typed error. .NET 8, with the BCL's System.Net.Http; its only runtime dependency is Newtonsoft.Json. A CropPathClient is thread-safe: create one per base URL and credential, share it, and dispose of it when your application stops.

Download the CropPath.Sdk package (a .nupkg file) and its .sha256 file from this portal's Downloads page (/developers/downloads) into a folder, check its SHA-256, then use that folder as a local NuGet source as below. CropPath distributes its SDKs only through this portal, not through public package registries.

mkdir -p ~/croppath-packages && cd ~/croppath-packages
curl -fLO https://txng.theio.vn/developers/downloads/sdk/CropPath.Sdk.0.3.0.nupkg
curl -fLO https://txng.theio.vn/developers/downloads/sdk/CropPath.Sdk.0.3.0.nupkg.sha256
sha256sum -c CropPath.Sdk.0.3.0.nupkg.sha256    # macOS: shasum -a 256 -c CropPath.Sdk.0.3.0.nupkg.sha256
dotnet nuget add source ~/croppath-packages --name croppath-local
cd -                                            # back to your project
dotnet add package CropPath.Sdk --version 0.3.0
using CropPath.Sdk;
using CropPath.Sdk.Generated.Model;

using var client = new CropPathClient(new CropPathClientOptions
{
    BaseUrl = "https://txng.theio.vn",
    ApiToken = Environment.GetEnvironmentVariable("CROPPATH_TOKEN"),   // an API token: Settings > API tokens
    Tenant = "coop-dl",                                                 // sent as X-Tenant
});

Lot lot = await client.Lots.GetLotAsync("LO-260928-014");
Console.WriteLine(lot.Status);

Credentials: an API token, or OAuth2 client credentials (the client asks /v1/oauth/token for a short-lived token with its id and secret, reuses it until shortly before it expires, and asks for a new one once when the API answers 401), or a token source of your own. The token is sent only as Authorization: Bearer and only to the base URL; redirects are never followed; the base URL must be https:// except for a loopback address (localhost); and no error message contains a token or a secret.

Retries: the POSTs that take an Idempotency-Key (create lot, open session, allocate fruit, cartons, seal, shipment, depart, ...) get a random key when you set none, and keep it on every retry, so the API replays its stored answer instead of running the action twice. Set your own key when you store it with your record of the action. Only GET, HEAD and those POSTs are retried: after a network error, a timeout, 429, 502, 503 or 504 (and 409 idempotency_key_in_use for a keyed POST), 3 attempts in all by default, honouring Retry-After up to 30 seconds. Every other write is sent once: after a lost answer, read the resource back before you send it again.

Also included: typed errors by HTTP status (with the API's code and the request id), pagination helpers that follow next_cursor and always stop (by default after 1,000 pages, and 10,000 items when collecting a whole list), the live streams of a measurement session and of the device message log (reconnecting with Last-Event-ID), and a webhook verifier that compares the signature in constant time and refuses a timestamp more than 300 seconds from your clock.

In the API reference