Open MercatoDocsSearch docsAPI reference

REST API

REST API Overview

A REST request needs a route, credentials and the right access scope. Start with one authenticated read, then inspect the endpoint's request and response schemas.

Open the API Explorer at /docs/api on your Open Mercato instance to inspect request and response schemas or try a call with an API key.

The Open Mercato REST API is auto-discovered from each module under src/modules/<module>/api. Every handler is expressed as a standard Next.js route.ts module and is wrapped in shared infrastructure that enforces authentication, scoping, and feature checks. Use this page as the launch pad before diving into the detailed module guides.

Base URL

All paths shown below are relative to the /api base.

Quick Start Environment

export BASE_URL="http://localhost:3000/api"
export API_KEY="<paste your API key secret here>"
export ORG_ID="<optional active organization id>"

API_KEY comes from the admin UI table (Settings → Auth → API Keys, /backend/api-keys) or the mercato api_keys add CLI command. All curl examples reuse these variables so you can copy, tweak, and run them immediately.

Authentication Flow

  1. Mint a key from the Managing API keys guide or via mercato api_keys add. Keys inherit the roles (and therefore features) you assign.
  2. Send the secret on every request using either X-Api-Key: <secret> or Authorization: ApiKey <secret>. The prefix (the omk_xxxxxxxx part before the dot) helps correlate requests with a specific key.
  3. Requests lacking a valid API key receive 401 Unauthorized. Deleted or expired keys behave the same.

Human users still sign in with email/password for the admin UI, but machine-to-machine integrations should rely on API keys for predictable scoping and auditability.

Feature Gates & Access Control

Each HTTP method exports metadata declaring requireAuth, requireRoles, and requireFeatures. The RBAC service evaluates the metadata against the authenticated principal:

Tenant and Organization Scoping

Full examples live in the Directory service guide.

Request & Response Conventions

Error Semantics & Status Codes

Tooling & Automation

Documentation & Playground

Module Guides

With these conventions in mind, hop into the module-specific pages for endpoint breakdowns, sample payloads, and extensive curl recipes you can adapt for your own tooling.

Previous: Module registry API · Next: Payment gateway API