CropPath for developers

All guides

Go SDK

Available

A typed client of the HTTP API for services written in Go.

croppath is a typed Go client of the whole HTTP API, for packing houses and ERP integrations: every operation is a method of the generated package gen (client.LotsAPI.GetLot(ctx, ...), then Execute()), and every call takes a context.Context. Go 1.22 or later; no dependency outside the Go standard library. A Client is safe for concurrent use: build one per base URL and credential and share it.

The Go SDK's import path is txng.theio.vn/sdk/go, and only this portal serves the module: set GOPRIVATE so the go command fetches it from the portal directly, never through a public module proxy or checksum database, then run go get as below (Go 1.22 or later). Check the two txng.theio.vn/sdk/go v0.3.0 lines go get added to your go.sum against the go_sum lines of index.json on the Downloads page (/developers/downloads). CropPath distributes its SDKs only through this portal, not through public package registries.

go env -w GOPRIVATE=txng.theio.vn      # or add txng.theio.vn to GONOPROXY and GONOSUMDB
go get txng.theio.vn/sdk/go@v0.3.0
import (
	croppath "txng.theio.vn/sdk/go"
)

client, err := croppath.New("https://txng.theio.vn",
	croppath.WithAPIToken(os.Getenv("CROPPATH_TOKEN")), // Settings > API tokens
	croppath.WithTenant("coop-a"))
if err != nil {
	log.Fatal(err)
}

lot, _, err := client.LotsAPI.GetLot(ctx, "LO-2026-0001").Execute()
switch {
case errors.Is(err, croppath.ErrNotFound):
	// no such lot in this tenant
case err != nil:
	log.Fatal(err)
default:
	fmt.Println(lot.GetStatus())
}

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