Skip to content

jobs

Create import jobs, run them batch by batch, read their records and roll them back. This page also covers what every Flux Importer route has in common.

Every Flux Importer route lives under /_emdash/api/plugins/fluximporter/. The admin’s Imports page uses the same routes, so anything it does, you can script. Each route is a POST with a JSON body, except jobs/log.csv, which is a GET.

Only Administrators can call these routes: each one needs EmDash’s import:execute permission. Authenticate in one of two ways:

  • From the browser, with the Administrator’s EmDash session cookie. Add the header X-EmDash-Request: 1 to every request, GET included, or EmDash refuses it with CSRF_REJECTED.
  • From a script or server, with a bearer token: a personal access token (ec_pat_…, created in the EmDash admin) or an OAuth access token. The token needs the admin scope and must belong to an Administrator. Token requests don’t need the X-EmDash-Request header.
Authorization: Bearer $EMDASH_TOKEN

Keep tokens in environment variables, never in your repository.

Send the body as JSON with Content-Type: application/json. Send {} when a route takes no fields. Unknown keys are refused on routes marked strict below, and ignored on the others.

Every answer uses EmDash’s envelope. A success is HTTP 200 with the route’s result in data:

{ "success": true, "data": { "items": [], "hasMore": false } }

A failure has an HTTP error status, a stable code and a message. Some errors add details, such as details.problems (a list of strings) for a template that doesn’t fit:

{
"success": false,
"error": { "code": "TEMPLATE_CHANGED", "message": "Template 01JDQ6Y2B9C4D7E1F3G5H8J0KM is at revision 4, not 3; read it again", "details": { "revision": 4 } }
}

Lists answer one page at a time as { items, hasMore, cursor? }. Pass cursor back to get the next page; it’s there while hasMore is true.

Code Status Meaning
UNAUTHORIZED 401 No session or token, or it has expired.
FORBIDDEN 403 The user isn’t an Administrator (import:execute).
INSUFFICIENT_SCOPE 403 The token lacks the admin scope.
CSRF_REJECTED 403 A session request without X-EmDash-Request: 1.
NOT_FOUND 404 No such route, or the item the route names doesn’t exist.
METHOD_NOT_ALLOWED 405 The route takes another method.
VALIDATION_ERROR 400 The body doesn’t match the route’s schema. details says which field.
INVALID_PLUGIN_REQUEST 400, 413 The body isn’t valid JSON, or is over the route’s size limit.
INVALID_CURSOR 400 The cursor isn’t valid. Start again without it.
STORAGE_INDEXES_NOT_READY 503 EmDash is still building the plugin’s storage indexes. Try again shortly.
PLUGIN_SYNC_ERROR 503 EmDash couldn’t load the plugin just now. Try again shortly.
INTERNAL_ERROR 500 An unexpected error. The message is always “Plugin route error”.

Each route below lists the errors of its own. See Error codes for what the admin shows for each.

POST /_emdash/api/fluximporter/uploads?filename=products.csv

This route is not under plugins/: fluxImporterRoutes() adds it, so files can be larger than EmDash allows for a plugin request. The request body is the file itself, not JSON, and is streamed into your site’s storage. Authentication is the same as for the other routes.

  • filename (query, required): 1 to 255 characters, with no /, \ or NUL, ending in .csv, .json, .jsonl, .ndjson, .xml or .xlsx (any case). The extension only decides whether the file is accepted and which size limit applies. The template’s source.format decides how it’s read.
  • Size limit: maxSourceBytes (default 50 MiB, an option of fluxImporterRoutes(), see Configuration). An .xlsx file is limited to 10 MiB, or maxSourceBytes if that’s lower.
  • On Cloudflare Workers the request must carry a Content-Length header. Browsers and curl send one for a file.

The answer is HTTP 201 with the upload ID, the size and the SHA-256 of the file. Pass the uploadId to jobs/create, sources/sample or templates/suggest.

Terminal window
curl -X POST "https://example.com/_emdash/api/fluximporter/uploads?filename=products.csv" \
-H "Authorization: Bearer $EMDASH_TOKEN" \
--data-binary @products.csv
// From the admin, with a File from an <input type="file">.
const res = await fetch(
`/_emdash/api/fluximporter/uploads?filename=${encodeURIComponent(file.name)}`,
{ method: "POST", headers: { "X-EmDash-Request": "1" }, body: file },
);
const { data } = await res.json();
{
"success": true,
"data": {
"uploadId": "01JDQ7M3X8K4N2P5R6S7T8V9WA3f9c2a7e5b1d4c6a8e0f2b4d6a8c0e1f",
"bytes": 18734,
"sha256": "5f2b8c1e9a7d4f6b3c0e2a8d1f7b9c4e6a3d0f5b8e2c7a1d9f4b6e3c0a8d2f7b"
}
}
Code Status Meaning
UNSUPPORTED_SOURCE 415 filename is missing or doesn’t end in an accepted extension.
TOO_LARGE 413 The file is over the size limit.
LENGTH_REQUIRED 411 On Workers, the request has no Content-Length.
EMPTY_BODY 400 The body is empty.
FORBIDDEN 403 The user isn’t an Administrator.
NOT_CONFIGURED 500 EmDash has no storage configured.

Staged files are deleted with the job logs, after the number of days set in the plugin settings (30 by default).

Route What it does MCP tool
jobs/create Creates a job or a dry run none
jobs/next Runs one batch of a job none
jobs/get Reads a job none
jobs/list Lists jobs, newest first none
jobs/summaries Lists jobs as the admin’s Jobs tab shows them none
jobs/records Lists a job’s records none
jobs/log.csv Downloads a job’s log as CSV none
jobs/pause, resume, cancel, retry Changes a job’s state none
jobs/rollback Creates the rollback of an import none
jobs/clear-dry-runs Deletes old dry runs none
jobs/plan An agent’s dry run from a saved template fluximporter__dry_run
jobs/start Runs an agent’s dry run for real fluximporter__start_import
jobs/step Runs one batch of an agent’s job fluximporter__next_batch
jobs/status Reads any job’s summary fluximporter__import_status

A job’s id is 1 to 64 characters from A-Z, a-z, 0-9, _ and -. For what each status and record outcome means, see Job states and record outcomes.

Creates an import job, or a dry run, from an upload or a URL source and a template. It has its own page: jobs/create.

POST /_emdash/api/plugins/fluximporter/jobs/next

Runs one batch of a job and answers with the job. A job doesn’t run by itself: call jobs/next until its status is completed, failed, paused or cancelled. Rollback jobs run the same way.

A batch processes up to the job’s batchSize records within its budgetMs. On Cloudflare Workers it processes fewer, to stay within the platform’s limits. When the job is neither created nor running, or another call is running a batch of it, the job comes back unchanged without a batch, so it’s safe to call from two tabs.

Field Type Required Notes
id string yes The job’s ID.

Response: the job row, with its status, cursor, counters (created, updated, unchanged, locked, conflict, failed, filtered, and reverted and removed when they apply), warnings and error.

Errors: NOT_FOUND (404).

Terminal window
curl -X POST "https://example.com/_emdash/api/plugins/fluximporter/jobs/next" \
-H "Authorization: Bearer $EMDASH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"id":"01JDQ8B5ZK3W9Y7C2M4N6P8R0T"}'
// Drive a job to the end from the admin.
async function run(id) {
for (;;) {
const res = await fetch("/_emdash/api/plugins/fluximporter/jobs/next", {
method: "POST",
headers: { "Content-Type": "application/json", "X-EmDash-Request": "1" },
body: JSON.stringify({ id }),
});
const { data: job } = await res.json();
if (["completed", "failed", "paused", "cancelled"].includes(job.status)) return job;
}
}

POST /_emdash/api/plugins/fluximporter/jobs/get

Reads a job without running it.

Field Type Required Notes
id string yes The job’s ID.

Response: the job row, as jobs/next returns it. Errors: NOT_FOUND (404).

POST /_emdash/api/plugins/fluximporter/jobs/list

Lists job rows, newest first, 8 a page. Dry runs and rollbacks are included.

Field Type Required Notes
status string no Only jobs with this status: created, running, paused, completed, cancelled or failed.
templateId string no Only jobs made from this saved template, and their rollbacks.
cursor string no 1 to 1,024 characters, from the previous page.

Response: { items, hasMore, cursor? }, where items are job rows.

POST /_emdash/api/plugins/fluximporter/jobs/summaries · strict

Lists jobs as the Jobs tab shows them: real imports, or dry runs, newest first, 8 a page. Each item holds only what the table needs, with no template, upload IDs or error message.

Field Type Required Notes
dryRun boolean no true lists dry runs instead of real imports. Default false.
status string no From version 0.9.0: only jobs with this status, such as running or failed.
cursor string no From the previous page.

Response: { items, hasMore, cursor?, total? }. From version 0.9.0, the first page (no cursor) has total, the exact number of jobs that match. Each item has id, kind (import or rollback), status, dryRun, collection, locale, rollbackable, counters, createdAt and updatedAt, and, when they apply, progress (processed of total records, while an import with a known record count reads its records), origin (agent, schedule or wizard), scheduleId, templateId, rollbackOf, rolledBackBy, rollbackStatus, startedAs and errorCode.

POST /_emdash/api/plugins/fluximporter/jobs/records

Lists a job’s records in source order, 50 a page. A dry run’s records show what it would do.

Field Type Required Notes
id string yes The job’s ID.
status string no Only records with this outcome: writing, created, updated, unchanged, locked, conflict, failed, planned, filtered, reverted or removed.
facet string no From version 0.9.0: change for records that create, update or remove an entry, or warning for records with a warning, as Preview’s Will change and Warnings filters show them. Records of a job that ran before 0.9.0 have no facet.
cursor string no From the previous page.

Response: { items, hasMore, cursor? }. Each record has seq (its position), status, sourceKey, entryId and updatedAt, and, when they apply, action, changes, errors and warnings (each { field?, code, message }), newTerms and newMedia.

Errors: NOT_FOUND (404).

GET /_emdash/api/plugins/fluximporter/jobs/log.csv?id=…&status=…

Downloads a job’s records as a CSV file named fluximporter-<id>.csv, with the columns record, status, source_key, entry_id, action, error_code, error_field, message and warnings. The input is in the query string: id (required) and status (optional, one record outcome as in jobs/records). The answer is the file itself, not the JSON envelope. Session requests still need X-EmDash-Request: 1, so download it with fetch, not a plain link.

Terminal window
curl "https://example.com/_emdash/api/plugins/fluximporter/jobs/log.csv?id=01JDQ8B5ZK3W9Y7C2M4N6P8R0T&status=failed" \
-H "Authorization: Bearer $EMDASH_TOKEN" -o failed.csv

Errors: NOT_FOUND (404); LOG_TOO_LARGE (413) when the log is over 8 MiB: download it one status at a time.

jobs/pause, jobs/resume, jobs/cancel, jobs/retry

Section titled “jobs/pause, jobs/resume, jobs/cancel, jobs/retry”

POST /_emdash/api/plugins/fluximporter/jobs/pause (and resume, cancel, retry)

Each takes { "id": "…" } and answers with the changed job.

Route Allowed from Result
jobs/pause created, running paused
jobs/resume paused, failed running; the error is cleared
jobs/cancel created, running, paused, failed cancelled; can’t be undone
jobs/retry completed, real runs only running again, to re-process its failed, conflict and locked records

A rollback job can’t be cancelled; pause it, or resume it to finish. A job that was rolled back can’t be resumed or retried. Cancelling a scheduled job pauses its schedule.

Errors: NOT_FOUND (404); INVALID_TRANSITION (409) when the job’s state doesn’t allow it.

POST /_emdash/api/plugins/fluximporter/jobs/rollback

Creates the rollback job of a finished import: it deletes the entries the import created and puts back the ones it changed or removed, from the import’s journal. Drive it with jobs/next. Run a dry rollback first to see what it would do. Media and terms the import created are kept; the rollback’s warnings list them. See Rollback.

Field Type Required Notes
id string yes The import job to roll back.
dryRun boolean no true plans the rollback without changing anything. Default false.
batchSize integer no 1 to 500, default 50.
budgetMs integer no 500 to 25,000, default 4,000.

Response: the new rollback job (kind: "rollback", rollbackOf naming the import), with the status created. A real rollback marks the import rolledBackBy, lets its URL source import the same content again, and pauses the schedule that ran it.

Errors: NOT_FOUND (404); INVALID_OPTIONS (400) for batchSize or budgetMs out of range; INVALID_TRANSITION (409) when the job can’t be rolled back: it’s a dry run or a rollback, it has no journal, it was already rolled back, it’s still created, running or paused (cancel it first), a batch is running, or retention is deleting it.

POST /_emdash/api/plugins/fluximporter/jobs/clear-dry-runs · strict

Deletes old dry runs and their records, as Clear dry runs does on the Jobs tab. Each call checks the 20 oldest dry runs. It deletes a dry run that finished or hasn’t changed for an hour, and an agent’s dry run that was never started and hasn’t changed for 24 hours. It never touches a real import, or a dry run a batch is running.

Field Type Required Notes
cursor string no From the previous answer.

Response: { cleared, more, cursor? }: how many it deleted, and whether to call again. While more is true, call again with the cursor it gave, or without one when it gave none.

These four routes are the MCP tools that AI agents use, and work the same over HTTP. They only take saved templates, never remove missing entries, and always keep a journal on a real run. Their schemas are strict, and they answer with summaries rather than job rows. Upload IDs in their messages are replaced with [staged file]. See Agent tools for the full flow.

POST /_emdash/api/plugins/fluximporter/jobs/plan · strict · MCP tool fluximporter__dry_run

Creates a dry run from a saved template and either pasted text or a URL source. The body can be at most 2 MiB.

Field Type Required Notes
templateId string yes A saved template’s ID.
templateRevision integer ≥ 1 no Refuse with TEMPLATE_CHANGED unless the template is at this revision.
text string one of The data in the template’s format, at most 1 MiB. Not for XLSX templates.
sourceId string one of A URL source’s ID. It is fetched now. Set exactly one of text and sourceId.
publish boolean no Default true; false keeps written entries as drafts.
batchSize integer no 1 to 500, default 50.
budgetMs integer no 500 to 25,000, default 4,000.

Response: { job }, a job summary: id, kind, status, dryRun, phase, collection, locale, publish, missing, processed, counters, error, the first 10 warnings and warningCount, next, createdAt and updatedAt, plus templateId, templateRevision, origin and the other links when they apply.

Errors: VALIDATION_ERROR (400); TEMPLATE_NOT_FOUND (404); TEMPLATE_CHANGED (409); INVALID_FORMAT (400) for text with an XLSX template; EMPTY_BODY (400) and TOO_LARGE (413) for the text; INVALID_TEMPLATE, INVALID_OPTIONS and INVALID_SOURCE (400); the URL source errors of sources/fetch.

Terminal window
curl -X POST "https://example.com/_emdash/api/plugins/fluximporter/jobs/plan" \
-H "Authorization: Bearer $EMDASH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"templateId":"01JDQ6Y2B9C4D7E1F3G5H8J0KM","text":"sku,Name,Price\r\nSKU-1,Desk lamp,24.50\r\n"}'

POST /_emdash/api/plugins/fluximporter/jobs/start · strict · MCP tool fluximporter__start_import

Runs a completed jobs/plan dry run for real, with the same data, template revision and options. Calling it again with the same dryRunId returns the same job.

Field Type Required Notes
dryRunId string yes The completed dry run’s ID.
batchSize integer no 1 to 500. Default: the dry run’s.
budgetMs integer no 500 to 25,000. Default: the dry run’s.

Response: { job }, a job summary as for jobs/plan.

Errors: NOT_FOUND (404); NOT_A_DRY_RUN (400) when the job isn’t a jobs/plan dry run; DRY_RUN_INCOMPLETE (409) when it hasn’t completed or is being deleted; DRY_RUN_USED (409) when the import started from it was rolled back; TEMPLATE_CHANGED (409); SOURCE_FILE_MISSING (404) when its data is no longer stored; CONFLICT (409).

POST /_emdash/api/plugins/fluximporter/jobs/step · strict · MCP tool fluximporter__next_batch

Runs one batch of a job that jobs/plan or jobs/start created, like jobs/next, and answers with a short reply.

Field Type Required Notes
id string yes The job’s ID.

Response: { id, status, next, processed, total?, busyUntil?, retryAfterMs?, error? }. next is next_batch (call again, after retryAfterMs when it’s set), wait (another call holds the job: wait retryAfterMs), done or stopped (paused, failed or cancelled).

Errors: NOT_FOUND (404); JOB_NOT_AGENT (403) for a job the agent routes didn’t create.

POST /_emdash/api/plugins/fluximporter/jobs/status · strict · MCP tool fluximporter__import_status

Reads any job’s summary without running it, and optionally a page of its records.

Field Type Required Notes
id string yes The job’s ID.
records string no A record outcome, as in jobs/records. Adds up to 10 records with it.
cursor string no From the previous call with the same records.

Response: { job, records? }. job is a summary as for jobs/plan; its next is not_agent for an unfinished job the agent routes didn’t create. records is { items, hasMore, cursor? }, each item with short previews of the changed values and errors.

Errors: NOT_FOUND (404).