Skip to content

Quickstart

View .mdllms.txt

From nothing to listings on a page in four steps. The examples use TypeScript, but any language that can send HTTPS requests works.

Keys come from the marketplace’s team. In the console, API keys → New key, they create:

  • a secret key (sk_test_… or sk_live_…) for your server, and
  • optionally a publishable key (pk_…) for native apps.

A key is shown once. Keep the secret key out of your code and out of browsers: put it in an environment variable such as MONGRL_SECRET_KEY.

Environment API Keys
Test https://api.staging.mongrl.com sk_test_…, pk_test_…
Live https://api.mongrl.com sk_live_…, pk_live_…

Check a key:

Terminal window
curl https://api.staging.mongrl.com/v1/marketplace \
-H "Authorization: Bearer $MONGRL_SECRET_KEY"

The answer is your marketplace: its currencies, languages, what a listing needs and its shipping table.

The OpenAPI spec describes every endpoint and field. Generate a client from it instead of writing requests by hand: the compiler then catches wrong paths and fields.

Terminal window
npm install -D @hey-api/openapi-ts
curl -o openapi.json https://dev.mongrl.com/openapi.json
openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts'
export default defineConfig({
input: './openapi.json',
output: { path: 'src/api/generated' },
plugins: ['@hey-api/client-fetch'],
})
Terminal window
npx openapi-ts

Each operation becomes a typed function named after its operation id: listListings, getListing, placeOrder… Commit the spec with your code and update it on purpose, so a new API version never changes your build by surprise.

Make the client on the server, per request, with your secret key and (when someone is signed in) their session. Never import it into code that runs in the browser.

// src/server/mongrl.ts (server only)
import { createClient } from '../api/generated/client'
export function mongrl(session?: string) {
return createClient({
baseUrl: process.env.MONGRL_API_URL, // https://api.staging.mongrl.com
auth: () => process.env.MONGRL_SECRET_KEY, // sent as Authorization: Bearer sk_…
headers: session ? { 'X-User-Session': session } : undefined,
})
}
import { listListings } from '../api/generated'
import { mongrl } from './mongrl'
const { data, error } = await listListings({
client: mongrl(),
query: { q: 'lounge chair', currency: 'EUR', limit: 24 },
})
if (error) throw new Error(error.detail)
for (const l of data.items ?? []) {
console.log(l.title, l.display_price?.amount, l.images?.[0]?.urls?.medium)
}

display_price is the price in the currency you asked for. Amounts are minor units: 125000 with SEK is 1 250,00 kr.

Requests for a user (their orders, their listings, buying) also send the user’s session token. Your server gets it when the user signs in and keeps it in an HttpOnly cookie:

import { listMyOrders, signIn } from '../api/generated'
const { data } = await signIn({ client: mongrl(), body: { email, password } })
// Store data.session.token in an HttpOnly, Secure, SameSite=Lax cookie.
const orders = await listMyOrders({ client: mongrl(tokenFromCookie) })

Authentication explains keys and sessions in full.