SDKs
The recommended way to consume the MGX Enterprise API is through an official SDK. We ship five — TypeScript/Node, Python, .NET, Java, and PHP — all generated from the same OpenAPI contract, so every language exposes the identical surface: the same resource namespaces, the same OAuth2 flows, and the same conventions for pagination, idempotency, and errors. Learn it once, use it anywhere.
All five SDKs are open source and developed in the public mygrainexchange/mgx-sdks repository.
Official libraries
Shared features
Because each SDK is generated from the same contract and finished with a hand-written ergonomics overlay, every language gives you the same guarantees:
- Name
OAuth2 authentication- Type
- built-in
- Description
- Configure a single client with your clientId and clientSecret. The SDK acquires, caches, and auto-refreshes the access token and attaches Authorization: Bearer to every request — both client-credentials (read scopes) and authorization-code / Login with MGX (user-context scopes).
- Name
Auto-pagination- Type
- built-in
- Description
- list() returns a lazy iterator that transparently follows the next link across the items envelope until exhausted. Just iterate.
- Name
Automatic idempotency keys- Type
- built-in
- Description
- Write operations that need it — inventory.placeBid and cashBids.create — generate and send an Idempotency-Key when you don't supply one, so retries are safe.
- Name
Typed errors- Type
- built-in
- Description
- The API error envelope maps to a typed MgxApiError exposing status, code, message, and field errors.
- Name
Automatic retries- Type
- built-in
- Description
- Idempotent GETs and any request carrying an Idempotency-Key are retried on 429/5xx with exponential backoff, up to maxRetries.
The resource namespaces are the same in every SDK: inventory, market, bids, trades, teams, cashBids (cash_bids in Python), and webhooks.
Your first request
Here is the same first request — browsing wheat inventory of at least 50 tonnes — in all five languages. Each constructs one client with your credentials and the read scopes, then iterates the auto-paginating inventory.list.
Browse inventory
import { MgxClient } from '@mygrainexchange/sdk'
const mgx = new MgxClient({
clientId: process.env.MGX_CLIENT_ID!,
clientSecret: process.env.MGX_CLIENT_SECRET!,
scopes: ['inventory.read', 'market.read'],
})
for await (const lot of mgx.inventory.list({ commodity: 'wheat', minQuantity: 50 })) {
console.log(lot.id, lot.quantityMt, lot.askingPrice?.amount)
}
For bidding and team-scoped reads, authenticate the same client through Login with MGX so the token is bound to a team. See the Quickstart for the full register → token → request walkthrough, and each resource page for SDK examples of the rest of the surface.