Open MercatoDocsSearch docsAPI reference

REST API

Export data through the API

Use the filters from a working list request to export the same selection of records. Choose the output format according to the application that will read the file.

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.

Most list endpoints in Open Mercato can return a downloadable file instead of a paginated JSON page. Export is a cross-cutting capability of the CRUD factory: you do not call a separate /export route – you add a format query parameter to the same list URL you already use. This page documents that contract plus the two bespoke export endpoints (custom entity records and audit logs).

export BASE_URL="http://localhost:3000/api"
export API_KEY="<paste your API key secret here>"

All curl examples reuse these variables. Provision the API key with the same features the underlying list endpoint requires (see Managing API keys).

How exporting works

The serializers live in packages/shared/src/lib/crud/exporters.ts; the CRUD factory wires them into every list route in packages/shared/src/lib/crud/factory.ts.

Exporting any CRUD list endpoint

Export is enabled by default on every list endpoint built with makeCrudRoute. A route only turns it off with list.export.enabled = false, or narrows the offered formats with list.export.formats (see Configuring export on a route).

Query parameters

ParameterValuesDescription
formatcsv | json | xml | markdownRequired to trigger an export. Case-insensitive; MIME aliases (application/json, application/xml, text/markdown) and md are also accepted. An unknown/unavailable value falls through to a normal JSON list response.
exportScopeview (default) | fullview exports the grid projection (the same columns the list shows). full exports the full raw records – all fields, including flattened custom fields, with internal _meta/enricher fields removed. export_scope is accepted as a snake-case alias.
fulltrue | falseAlias for exportScope=full.
alltrue | falseBypasses pagination; the admin UI sets it on full exports.

Every filter, search, and sort parameter the list endpoint already supports also applies to the export.

Available formats

formatContent-TypeFile extension
csvtext/csv; charset=utf-8.csv
jsonapplication/json; charset=utf-8.json
xmlapplication/xml; charset=utf-8.xml
markdowntext/markdown; charset=utf-8.md

Response

The body is the serialized file. Two headers describe it:

When the query index backing the list is known to be incomplete, the response also carries an x-om-partial-index header with a JSON payload describing the gap, so clients can warn that the export may be missing rows.

Examples

Export the current filtered view of a list as CSV:

curl -X GET "$BASE_URL/customers/people?format=csv&search=acme&sortField=created_at&sortDir=desc" \
  -H "X-Api-Key: $API_KEY" \
  -o people.csv

Export full raw records as JSON:

curl -X GET "$BASE_URL/customers/people?format=json&exportScope=full&all=true" \
  -H "X-Api-Key: $API_KEY" \
  -o people_full.json

Export a specific subset by id as Markdown:

curl -X GET "$BASE_URL/catalog/products?format=markdown&ids=$PRODUCT_A,$PRODUCT_B" \
  -H "X-Api-Key: $API_KEY" \
  -o products.md

The same pattern works for any makeCrudRoute list, e.g. catalog/products, sales/<document>, customers/companies, and customers/deals.

Column selection

There is no per-request column-selection parameter. The exported columns are fixed by the route:

Exporting custom entity records

Custom (EAV) entity records have their own list endpoint, and it supports the same format parameter. See the Entities & Custom Fields API for the full endpoint.

curl -X GET "$BASE_URL/entities/records?entityId=example.todo&format=csv" \
  -H "X-Api-Key: $API_KEY" \
  -o todos.csv

Implementation: packages/core/src/modules/entities/api/records.ts.

Exporting audit logs

The audit-log changelog has a dedicated export endpoint that always returns CSV.

Filter parameters (all optional):

ParameterDescription
organizationIdLimit to a specific organization (must be in the caller's allowed scope).
actorUserIdFilter by actor. Single UUID or comma-separated list (tenant administrators only).
resourceKind / resourceIdFilter by resource type (e.g. order, product) and/or a specific record.
actionTypecreate, edit, delete, assign, … – single value or comma-separated list.
fieldNameOnly entries where the given field(s) changed.
includeRelatedtrue/false – include changes to child entities linked via parent resource.
undoableOnlytrue/false – only undoable actions.
limitMax rows (default 1000, capped at 1000).
sortFieldcreatedAt | user | action | field | source.
sortDirasc | desc.
before / afterISO-8601 timestamps bounding the range.
curl -X GET "$BASE_URL/audit-logs/actions/export?resourceKind=order&actionType=edit,delete&after=2026-01-01T00:00:00Z" \
  -H "X-Api-Key: $API_KEY" \
  -o changelog.csv

Implementation: packages/core/src/modules/audit_logs/api/audit-logs/actions/export/route.ts.

Configuring export on a route

Module authors control export behavior through the list.export block passed to makeCrudRoute. See the CRUD Factory reference for the full option set.

list: {
  entityId: E.customers.person,
  export: {
    enabled: true,                 // default true; set false to disable export entirely
    formats: ['csv', 'json'],      // default: all four; restrict the offered set
    filename: 'customers_export',  // string or (format) => string
    columns: [                     // view-scope column projection
      { field: 'id', header: 'ID' },
      { field: 'display_name', header: 'Name' },
      { field: 'cf:priority', header: 'Priority' },
    ],
    batchSize: 1000,               // rows per in-request fetch page (clamped 100–10000)
  },
}

Notes and limitations

Previous: Entities and custom fields API · Next: Feature toggle API