REST API
An entity definition describes a record type. Field definitions describe the values it accepts, and the records endpoint handles the values themselves.
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.
Entity extensibility is central to Open Mercato. Every endpoint published by the module lives under /api/entities/*; the tables below list the suffix you append to your API origin.
export BASE_URL="http://localhost:3000/api"
export API_KEY="<paste your API key secret here>"
export ENTITY_ID="example.todo" # generated or custom entity id
export CUSTOM_ENTITY_ID="<uuid from POST /entities/entities>"
export RECORD_ID="<record uuid>"
Provision an API key with the required entities.* features as described in Managing API keys. Feature flags are defined in packages/core/src/modules/entities/acl.ts:1.
Heads-up: The dispatcher checks feature requirements exported from each route’s
metadata. If a call returns403, confirm the feature listed in the section header is granted to the caller.
/entities/entitiesGET /entities/entitiespackages/core/src/modules/entities/api/entities.ts:8).curl -X GET "$BASE_URL/entities/entities" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
POST /entities/entitiesentities.definitions.manage.upsertCustomEntitySchema (packages/core/src/modules/entities/data/validators.ts:72):
entityId (string) identifies the logical entity (e.g. custom.ticket).label, optional description, labelField, defaultEditor, showInSidebar.isActive (default true).curl -X POST "$BASE_URL/entities/entities" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"entityId": "custom.ticket",
"label": "Support Ticket",
"description": "Tenant defined issue tracker",
"labelField": "title",
"defaultEditor": "markdown",
"showInSidebar": true
}'
DELETE /entities/entitiesentities.definitions.manage.{ "entityId": "<id>" }; the implementation scopes deletion to the caller’s tenant/org (packages/core/src/modules/entities/api/entities.ts:121).curl -X DELETE "$BASE_URL/entities/entities" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{ "entityId": "custom.ticket" }'
GET /entities/sidebar-entitiespackages/core/src/modules/entities/api/sidebar-entities.ts:7).showInSidebar so you can build scoped navigation.curl -X GET "$BASE_URL/entities/sidebar-entities" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
/entities/definitions*GET /entities/definitionspackages/core/src/modules/entities/api/definitions.ts:8).entityId=<id> parameters or a comma-delimited entityIds query.packages/core/src/modules/entities/api/definitions.ts:120).curl -X GET "$BASE_URL/entities/definitions?entityId=$ENTITY_ID" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
GET /entities/definitions.manageentities.definitions.manage.{ items, deletedKeys }, showing winners per scope plus keys tombstoned in the current tenant/org (packages/core/src/modules/entities/api/definitions.manage.ts:15).curl -X GET "$BASE_URL/entities/definitions.manage?entityId=$ENTITY_ID" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
POST /entities/definitionsentities.definitions.manage.upsertCustomFieldDefSchema (packages/core/src/modules/entities/data/validators.ts:97):
entityId, key, kind.configJson lets you set label, options, filterable, listVisible, formEditable, dictionaries, validation rules, and editor hints.isActive soft disables fields without deleting history.curl -X POST "$BASE_URL/entities/definitions" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"key\": \"priority\",
\"kind\": \"enum\",
\"configJson\": {
\"label\": \"Priority\",
\"options\": [\"low\", \"medium\", \"high\"],
\"filterable\": true,
\"listVisible\": true
},
\"isActive\": true
}"
POST /entities/definitions.batchentities.definitions.manage.{ entityId, definitions: [ ... ] } lets you send an ordered array of definition payloads (packages/core/src/modules/entities/api/definitions.batch.ts:19).fieldsets array (matching customFieldsetSchema) and singleFieldsetPerRecord flag let you manage the drop-down metadata programmatically. Each field definition can also set configJson.fieldset and configJson.group to map the field into the new layout.curl -X POST "$BASE_URL/entities/definitions.batch" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"definitions\": [
{ \"key\": \"status\", \"kind\": \"enum\", \"configJson\": { \"label\": \"Status\", \"options\": [\"open\",\"won\",\"lost\"], \"priority\": 0 } },
{ \"key\": \"assignee\", \"kind\": \"string\", \"configJson\": { \"label\": \"Assignee\", \"filterable\": true, \"priority\": 1 } }
],
\"fieldsets\": [
{
\"code\": \"customer_profile\",
\"label\": \"Customers · Profile\",
\"icon\": \"lucide:user\",
\"groups\": [
{ \"code\": \"identity\", \"title\": \"Identity\" },
{ \"code\": \"preferences\", \"title\": \"Preferences\" }
]
}
],
\"singleFieldsetPerRecord\": true
}"
DELETE /entities/definitionsentities.definitions.manage.{ "entityId": "...", "key": "..." } and marks the definition inactive (packages/core/src/modules/entities/api/definitions.ts:189).curl -X DELETE "$BASE_URL/entities/definitions" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"key\": \"priority\"
}"
POST /entities/definitions.restoreentities.definitions.manage.{ entityId, key } reactivates a tombstoned definition and invalidates the cache (packages/core/src/modules/entities/api/definitions.restore.ts:9).curl -X POST "$BASE_URL/entities/definitions.restore" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"key\": \"priority\"
}"
/entities/recordsGET /entities/recordsentities.records.view (packages/core/src/modules/entities/api/records.ts:18).entityId. Optional filters include:
page, pageSize (max 100), withDeleted.sortField, sortDir.format=csv|json|xml|markdown, exportScope=full, all=true, full=true.cf_.curl -X GET "$BASE_URL/entities/records?entityId=$ENTITY_ID&page=1&pageSize=25&sortField=created_at&sortDir=desc" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
POST /entities/recordsentities.records.manage.{ entityId, recordId?, values } where values is a flat object; prefixing cf_ is optional because the handler normalises keys (packages/core/src/modules/entities/api/records.ts:204).recordId triggers auto-generation; use this to support optimistic UI drafts.curl -X POST "$BASE_URL/entities/records" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"values\": {
\"title\": \"Onboard new merchant\",
\"description\": \"Kick off data import\",
\"cf_priority\": \"high\"
}
}"
PUT /entities/recordsentities.records.manage.{ entityId, recordId, values } with the same shape as the create payload (packages/core/src/modules/entities/api/records.ts:246).recordId is not a UUID, falls back to create semantics (useful for spreadsheet imports).recordId must match an existing, non-deleted record in the caller's organization; otherwise the handler answers 404 and writes nothing. Use POST /entities/records to create a record under a chosen id.curl -X PUT "$BASE_URL/entities/records" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"entityId\": \"$ENTITY_ID\",
\"recordId\": \"$RECORD_ID\",
\"values\": {
\"title\": \"Onboard new merchant (updated)\",
\"cf_priority\": \"medium\"
}
}"
DELETE /entities/recordsentities.records.manage.?entityId=...&recordId=...) or JSON body; deletion is soft and scoped to the active tenant/org (packages/core/src/modules/entities/api/records.ts:337).curl -X DELETE "$BASE_URL/entities/records?entityId=$ENTITY_ID&recordId=$RECORD_ID" \
-H "X-Api-Key: $API_KEY"
GET /entities/relations/optionsentities.definitions.view.packages/core/src/modules/entities/api/relations/options.ts:12):
entityId (target entity providing options).labelField (field used for display text).q (search), pageSize, cursor.curl -X GET "$BASE_URL/entities/relations/options?entityId=$ENTITY_ID&labelField=title&q=demo" \
-H "X-Api-Key: $API_KEY" \
-H "Accept: application/json"
Response example:
{
"items": [
{ "value": "6d44ce18-4bc7-49d6-8b25-a94288363f25", "label": "Demo Ticket" }
],
"nextCursor": null
}
createDefinitionsCacheKey and invalidateDefinitionsCache in packages/core/src/modules/entities/api/definitions.cache.ts:6. These utilities are meant for internal cache management when definitions change; there is no public HTTP route at /entities/definitions.cache, even though the generator lists the file for completeness.entities:definitions:<tenant> so UI fragments and API consumers observe new fields immediately.Pair these endpoints with the DI queryEngine for server-side filtering or plug them into shared admin components (packages/shared/src/lib/crud/factory.ts:23) to deliver tenant-aware experiences without rebuilding CRUD plumbing.
Previous: Tenant and organization API · Next: Export data through the API