Skip to main content
This recipe reads one town’s fee brackets from GET /api/v1/states, then quotes an order with POST /api/v1/orders/validate. Nothing is created, reserved or charged. The Next.js, FastAPI, Laravel and Spring forms are a route of your server, so your storefront shows delivery prices without the key. Every visitor shares your key’s per-minute budget with your orders, so the routes keep the towns in memory (no longer than a day) and call validate only for a real cart. Rate-limit each visitor with your app’s own limits. The routes return the customer’s figures, never the quote’s reward.

Prerequisites

  • MART_API_KEY: your API key, with catalog:read and orders:write.
  • MART_API_BASE: https://sandbox.mart.ps while you build, https://mart.ps when you go live.
  • MART_PRODUCT_ID: a product your key is offered.
  • MART_STATE_ID: a town’s states[].id, never a city’s id.
One runtime: cURL 7.84 or later with jq; Node 22.18 or later, which runs the .ts file as it is; Python 3.9 or later with httpx; PHP 7.4 or later with its curl extension; Go 1.22 or later; or Java 17 or later with Jackson (jackson-databind). Each file reads its variables from the environment and sets a timeout on every call. Run it on your own server: a browser or an app never holds the key.

Run the recipe

Verify the result

  • A bracket applies when the products total is at least its first figure and less than the second. The brackets are your account’s own.
  • valid: true means an order with the same body would pass every check now. Stock, prices and fees can still move: the created order’s figures are the ones that count.

Troubleshooting

Every other code is in the error catalog.