MassGain

MassGain API documentation

Read potato market prices, supply, signals, and research in a versioned JSON API.

Sandbox quickstart

Start a sandbox trial in Stripe test mode. Open the link in your checkout email to generate your key and copy it from the key screen. Your trial includes 100 actions over 15 days.

Choose your shell below. Both examples check your balance for free, then fetch one published crop uncertainty snapshot. The data request uses one action.

Bash on macOS or Linux

Paste the full block below. When prompted, paste your key and press Enter. The key stays hidden while you type.

{
read -r -s -p 'Paste your sandbox API key: ' MASSGAIN_API_KEY
printf '\n'
base='https://massgain.world/developers/api/v1'
call_id="quickstart-$(date +%s)-$$"

curl -fsS -w '\n' "$base/usage" -H "Authorization: Bearer $MASSGAIN_API_KEY"
curl -fsS -w '\n' "$base/legacy/ucui?limit=1" \
  -H "Authorization: Bearer $MASSGAIN_API_KEY" \
  -H "Idempotency-Key: $call_id"
}

Windows PowerShell

In Command Prompt, type powershell -NoProfile and press Enter. Paste the full block below into PowerShell. When prompted, copy the key from the key screen, return here, and press Enter.

. {
[void](Read-Host 'Copy your sandbox API key now, then press Enter')
$key = (([string](Get-Clipboard -Raw)) -replace '\s', '')
if ($key -notmatch '^mg_test_[a-f0-9-]{36}\.[a-f0-9]{64}$') {
  throw 'Copy the complete MassGain sandbox key, then run this block again.'
}
$base = 'https://massgain.world/developers/api/v1'
$headers = @{ Authorization = "Bearer $key" }

Invoke-RestMethod "$base/usage" -Headers $headers | ConvertTo-Json -Depth 10
$headers['Idempotency-Key'] = [guid]::NewGuid().ToString()
Invoke-RestMethod "$base/legacy/ucui?limit=1" -Headers $headers | ConvertTo-Json -Depth 10

Read the response

Look for "status": "ok", an observation in data.rows[0], and charged: 1. This example shows a fresh trial after its first data request.

{
  "status": "ok",
  "data": {
    "feed": "ucui",
    "source": "https://massgain.world/api/ucui.json",
    "basis": "Published crop uncertainty snapshot. It is not a price, yield, or production observation.",
    "rows": [
      {"date": "2026-11-26", "ucui_level": "NORMAL", "ruleset_version": "1.1.0", "notes": null}
    ],
    "offset": 0,
    "next_offset": 1
  },
  "usage": {"limit": 100, "used": 1, "remaining": 99, "trial_ends_at": "2026-12-12T00:00:00.000Z"},
  "charged": 1,
  "request_id": "123e4567-e89b-42d3-a456-426614174000"
}

Repeat just the data request with the same idempotency key to check for replayed: true, charged: 0, and the same remaining balance. For a different request, generate a fresh idempotency key. Keep the API key in your shell or secret manager.

Endpoint reference

Base URL https://massgain.world/developers/api/v1. All endpoints use GET. To configure a client, import the OpenAPI file and supply the key through the client’s bearer authentication setting.

PathReturns
/verifyVerify the key and return its scope. No action.
/usageRead the action balance and trial expiry. No action.
/datasetsList market datasets and their accepted query parameters.
/datasets/{id}Inspect available fields and the dataset’s source.
/datasets/{id}/observationsRead observations, with date bounds, filters, and pagination.
/signalsRead UCUI, MPI, or the current MSR.
/intelligence/currentRead recent market signals, UCUI updates, and article references.
/publicationsSearch MassGain articles and knowledge guides.
/publicationRead a publication by its canonical URL.
/legacy/fappPublished FAPP reference history.
/legacy/eexHistorical European processing potato references.
/legacy/ucuiPublished crop uncertainty snapshots.
/legacy/ucui-logCrop uncertainty events and supporting references.

Queries and pagination

Start with /datasets, then use /datasets/{id} to discover the response fields. Dataset queries use query.<parameter> to select an upstream scope and filter.<field> for exact, case-insensitive row matches. For example, use query.region for a dataset that lists region as an accepted parameter. Use path to select a specific field path.

For example, request /datasets/us_shipments/observations?limit=3 for recent U.S. shipment observations. Inspect /datasets/us_shipments for the field names and source metadata.

Observations accept from and to matching the series granularity (ISO date, month, or year). Use full ISO dates for signals and legacy feeds. Observations and legacy feeds support limit up to 40 and offset. Pass data.next_offset as the next request’s offset, keeping your other parameters the same. A null cursor marks the end of the returned results. If data.upstream_sample_limited is true, the source supplied a bounded sample. Each page with results uses an action.

Search /publications with kind, query, before, limit, and offset. Follow data.next_before to continue into older articles. Pass the returned url to /publication and use its next_offset for longer articles.

Preserve dates, units, market stage, and source provenance when comparing records. FAPP and EEX are reference series. MPI draws on physical cash-market observations and MSR is a synthetic reference. UCUI describes crop uncertainty.

Usage and retries

Successful data requests, including catalog and schema reads, use one action. Usage and verification checks, empty results, failed calls, and replays use zero actions. All keys for the same trial share one balance. A replacement key takes effect immediately.

Successful responses include data, status, charged, usage, and request_id. Usage contains limit, used, remaining, and trial_ends_at. You can also read X-MassGain-Remaining and X-MassGain-Charged from the headers.

Set a unique Idempotency-Key on data requests you may retry. Use up to 100 letters, digits, hyphens, or underscores. Retrying the same successful request with that value returns the original data and uses zero actions. Reusing the value on a different request returns 409. Start each new request with its own value.

Errors and support

Errors include error.code, error.message, and request_id. Save the request ID when contacting support.

HTTPHandling
400Review the request parameters and their accepted formats.
401Use the current key for an active sandbox trial.
404Check the endpoint or dataset ID.
405Use GET.
409Use a fresh idempotency key for a different request.
422Reduce the limit or select a narrower field path.
429Check for quota_exhausted or rate_limited. The sandbox rate limit is 30 requests per minute per account. For throttling, wait for Retry-After.
503Retry with backoff and the same idempotency key.