REST API
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.
http://localhost:3000/api<your-domain>/apiAll paths shown below are relative to the /api base.
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.
mercato api_keys add. Keys inherit the roles (and therefore features) you assign.X-Api-Key: <secret> or Authorization: ApiKey <secret>. The prefix (the omk_xxxxxxxx part before the dot) helps correlate requests with a specific key.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.
Each HTTP method exports metadata declaring requireAuth, requireRoles, and requireFeatures. The RBAC service evaluates the metadata against the authenticated principal:
auth.users.list) exposed by every module under src/modules/<module>/acl.ts./api/auth/users/acl). Super administrators bypass feature checks.403 Forbidden.tenantId, orgId).400 or 403.GET /directory/organization-switcher endpoint returns the organization tree the current user may access. Clients can persist a new selection by setting the om_selected_org cookie before subsequent API calls.Full examples live in the Directory service guide.
/login expects multipart/form-data or application/x-www-form-urlencoded).page (default 1) and pageSize (default 50, max 100 or 200 depending on the handler) and respond with { items, total, page, pageSize, totalPages }.format=csv|json|xml|markdown to a list endpoint to download the result set as a file instead of a JSON page. See the Exporting data guide.search, id, and module-specific filters such as roleIds or tenantId. Custom field filters use the cf_<key> convention and obey the custom field kind.sortField and sortDir (asc or desc).customFields or prefixed keys (cf_priority) in create/update payloads. The CRUD factory persists them automatically.Content-Type: application/json for JSON bodies and Accept: application/json on reads to opt into JSON responses.200 OK, 201 Created, 204 No Content).{ "error": "Invalid input" }).yarn dev to boot the stack locally; the API listens on port 3000.yarn generate regenerates routing metadata after you add or remove module APIs.createRequestContainer() to reuse the same dependency injection graph as production handlers.@open-mercato/shared/lib/crud/factory to ensure consistent pagination, scoping, and event emission logic.GET /docs/api opens the OpenAPI Explorer, an interactive playground generated from the live module registry. Access it from the admin UI once signed in, browse every operation, review example payloads, and paste an API token to execute authenticated requests against your chosen base URL.GET /api/docs/openapi returns the OpenAPI 3.1 JSON document for client generation, contract testing, or syncing external tooling.GET /api/docs/markdown serves the same specification as Markdown, ideal for quick sharing or feeding into LLM prompts.Requires features/roles description lines and the x-require-features / x-require-roles extensions) is served only to signed-in staff callers. Anonymous clients receive the same document with those internal identifiers stripped, so the ACL feature names of your deployment are never published.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.