Skip to content

schema

Add the fields and select options an import needs to a collection. The route only ever adds; it never changes or removes a field.

The route is a POST to /_emdash/api/plugins/fluximporter/schema/apply with a JSON body, and needs an Administrator. See Before you call the API for authentication, the response envelope and the errors any route can return. It is not an MCP tool.

POST /_emdash/api/plugins/fluximporter/schema/apply · strict

Plans the fields you list, or the fields a template maps, against a collection. Then, unless it’s a dry run, it creates the fields that are missing and adds missing options to select fields, in the order given. A field that exists with another type is reported as a conflict and left alone. Reference fields are never created: add those in the admin. The wizard uses this route when you choose to create the fields you map.

Running it twice is safe: the fields it created the first time plan as unchanged.

Field Type Required Notes
fields array one of 1 to 100 fields to add (below). Needs collection.
template object one of A template whose mapped fields to add. See Template format.
templateId string one of A saved template whose mapped fields to add. Set exactly one of fields, template and templateId.
collection string with fields 1 to 63 characters. With a template it’s optional, and must be the template’s collection.
addOptions boolean no Add missing options to existing select and multi-select fields. Default false: missing options are a conflict.
dryRun boolean no true plans and changes nothing. Default false.

Each item of fields:

Field Type Required Notes
slug string yes a-z first, then a-z, 0-9 and _, at most 63 characters. EmDash’s reserved slugs and flux_source_id are refused.
type string yes string, text, url, number, integer, boolean, datetime, select, multiSelect, json, slug, image, file or portableText.
label string no 1 to 200 characters, without leading or trailing spaces. Default: made from the slug.
options string[] no select and multiSelect only: 1 to 500 distinct options of 1 to 200 characters.
indexed boolean no Default false. Only for string, url, number, integer, boolean, datetime, select and slug.
searchable boolean no Default false.
translatable boolean no Default true.

The body can be at most 2 MiB.

Response: { collection, dryRun, changes, applied, error }. changes has one item per field: { field, action, type, options?, message? }, where action is create, add_options, unchanged or conflict, and message says why for a conflict. applied lists the fields created or given options. error is null, or the EmDash error that stopped the run part-way, with the fields applied before it still in applied.

Terminal window
curl -X POST "https://example.com/_emdash/api/plugins/fluximporter/schema/apply" \
-H "Authorization: Bearer $EMDASH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"collection": "products",
"fields": [
{ "slug": "price", "type": "number" },
{ "slug": "stock_status", "type": "select", "options": ["in_stock", "sold_out"] }
],
"dryRun": true
}'
// Add the fields a saved template maps, from the admin.
const res = await fetch("/_emdash/api/plugins/fluximporter/schema/apply", {
method: "POST",
headers: { "Content-Type": "application/json", "X-EmDash-Request": "1" },
body: JSON.stringify({ templateId: "01JDQ6Y2B9C4D7E1F3G5H8J0KM", addOptions: true }),
});
const { data } = await res.json();
{
"success": true,
"data": {
"collection": "products",
"dryRun": true,
"changes": [
{ "field": "price", "action": "unchanged", "type": "number" },
{ "field": "stock_status", "action": "create", "type": "select", "options": ["in_stock", "sold_out"] }
],
"applied": [],
"error": null
}
}
Code Status Meaning
VALIDATION_ERROR 400 A field request is invalid, fields has no collection, the template is invalid, or collection isn’t the template’s. The message names each problem.
COLLECTION_NOT_FOUND 404 No collection has this slug.
TEMPLATE_NOT_FOUND 404 No saved template has this templateId.
INVALID_PLUGIN_REQUEST 413 The body is over 2 MiB.

After you add fields, run npx emdash types in your site to update its generated types.