Quickstart
This guide gets you from zero to your first authenticated request in a few minutes.
1. Register an API client
In your MGX dashboard, click your name in the top-right corner and choose Developers, then register a client. Choose the scopes your integration needs, set a redirect URI (for Login with MGX), and copy the client id and client secret — the secret is shown only once.
2. Install an SDK
The fastest path is one of our official SDKs — they handle OAuth2 tokens, pagination, idempotency, and typed errors for you. Pick your language:
Install
npm i @mygrainexchange/sdk
3. Get a token and make your first request
For read-only access (inventory, market) use the client-credentials grant. The SDKs acquire and cache the token for you from your client id and secret — just construct a client and call. With curl, fetch a token first, then send it as a bearer token.
Browse inventory
import { MgxClient } from '@mygrainexchange/sdk'
// The client gets, caches, and refreshes the token automatically.
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)
}
You'll get back anonymized listings — commodity, grade, quantity, coarse location, and asking price, with no seller information.
For bidding and team-scoped reads, authenticate through Login with MGX instead, so the token is bound to a specific team.