Open MercatoDocsSearch docsAPI reference

REST API

Entities and custom fields 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 returns 403, confirm the feature listed in the section header is granted to the caller.

Custom entity catalogue – /entities/entities

List entities – GET /entities/entities

curl -X GET "$BASE_URL/entities/entities" \
  -H "X-Api-Key: $API_KEY" \
  -H "Accept: application/json"

Upsert custom entity – POST /entities/entities

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
  }'

Soft delete custom entity – DELETE /entities/entities

curl -X DELETE "$BASE_URL/entities/entities" \
  -H "X-Api-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "entityId": "custom.ticket" }'
curl -X GET "$BASE_URL/entities/sidebar-entities" \
  -H "X-Api-Key: $API_KEY" \
  -H "Accept: application/json"

Field definitions – /entities/definitions*

Load active definitions – GET /entities/definitions

curl -X GET "$BASE_URL/entities/definitions?entityId=$ENTITY_ID" \
  -H "X-Api-Key: $API_KEY" \
  -H "Accept: application/json"

Management snapshot – GET /entities/definitions.manage

curl -X GET "$BASE_URL/entities/definitions.manage?entityId=$ENTITY_ID" \
  -H "X-Api-Key: $API_KEY" \
  -H "Accept: application/json"

Upsert definition – POST /entities/definitions

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
  }"

Batch upsert – POST /entities/definitions.batch

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
  }"

Soft delete definition – DELETE /entities/definitions

curl -X DELETE "$BASE_URL/entities/definitions" \
  -H "X-Api-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"entityId\": \"$ENTITY_ID\",
    \"key\": \"priority\"
  }"

Restore definition – POST /entities/definitions.restore

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\"
  }"

Records – /entities/records

List records – GET /entities/records

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"

Create record – POST /entities/records

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\"
    }
  }"

Update record – PUT /entities/records

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 record – DELETE /entities/records

curl -X DELETE "$BASE_URL/entities/records?entityId=$ENTITY_ID&recordId=$RECORD_ID" \
  -H "X-Api-Key: $API_KEY"

Relation options – GET /entities/relations/options

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
}

Implementation helpers


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