Skip to content

Features

Bulk import

Included free on every install, every format included. Saved mapping templates and the date, split and lookup transforms need a license with the content-pro feature. See pricing.

Bulk import turns a file into entries. You map the file's columns onto the fields of one content type, check every row with a dry run, then import. Each row becomes an entry exactly as if it had been created in LyEve Console, with a revision when content history is on for the type. Every row's outcome is kept, rejected rows download as CSV, and a finished import can be rolled back.

In the console, imports are under Insight > Imports. New import opens a wizard in three steps, Source, Map and Check, and History lists every import with what it created, updated, skipped and rejected.

StepWhat happens
ReadThe file comes from an upload, base64 in file_data, or from source_url. Its format is taken from source_format or detected.
MapEach mapping sends one column to one field, with an optional conversion, default and transform.
CheckEvery row is checked against the mappings and the content type's rules. A dry run stops here.
WriteEach row is created, updated or skipped, in the background. New entries are drafts unless you map entry.status.
ReviewEach row's outcome is kept. Rejected rows download as CSV, and the import can be rolled back.

You need a content type post with a title text field and a body rich text field. Your first content type builds one. The file is one row, title,body then Hello,First post.

For the console steps, you are signed in to the console as an admin or super_admin, and the file is saved as posts.csv:

title,body
Hello,First post

For the API steps, you need a token in TOKEN for one. The quickstart shows how to get one. The API takes the file base64-encoded:

Shell
FD=dGl0bGUsYm9keQpIZWxsbyxGaXJzdCBwb3N0Cg==

1. Describe the file before you map it. Nothing is stored.

Console v0.28.0

  1. Open Insight > Imports and choose New import.
  2. Under Source, keep Upload a file and add posts.csv under File.
  3. Pick post in Content type, and keep Format at Read it from the file.
  4. Choose Read the file.

The Map step opens with 1 row of CSV from posts.csv and the row as a table.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/imports/preview \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"source_name\": \"posts.csv\", \"file_data\": \"$FD\"}"
JSON
{"source_format": "csv", "source_name": "posts.csv", "columns": ["title", "body"], "rows": [{"body": "First post", "title": "Hello"}], "total_rows": 1, "errors": [], "export": false, "schemas": {}}

2. Check every row against the mappings.

Console v0.28.0

  1. In Map, check the Column in the file for each field. The console guesses them from the column names, here title for Entry title and title, and body for body.
  2. Under When an entry already exists, keep Create only, and keep Key field at No key: every row is a new entry.
  3. Choose Dry run.

The Check step shows Rows in the file, Would import and Would be rejected, here 1, 1 and 0, with Every row passes. A rejected row is listed with its reason.

The Check step of a new import. Of 3 rows in the file, 2 would import and 1 would be rejected, row 3 for a missing title. Import 2 rows is at the bottom.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/imports/validate \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content_type\": \"post\", \"source_name\": \"posts.csv\", \"file_data\": \"$FD\", \"field_mappings\": [{\"source_field\": \"title\", \"target_field\": \"title\", \"required\": true, \"transform\": \"trim\"}, {\"source_field\": \"body\", \"target_field\": \"body\"}]}"
JSON
{ "total_rows": 1, "valid_rows": 1, "error_rows": 0, "errors": [] }

3. Start the import.

Console v0.28.0

Choose the import button, which names the count, here Import 1 row. The page confirms Import of posts.csv started, and the import appears at the top of History.

Engine API v0.62.0

Send the same body plus "source_format": "csv" and "mode": "create" to POST http://localhost:3001/api/admin/imports. The answer is 201 with the job and "status": "pending". Copy its id into JOB.

4. Check its progress.

Console v0.28.0

History lists the import with its outcome, here Every row imported, and how many rows it created, updated, skipped and rejected. Refresh reads it again. The rows button on its line lists each row's outcome. For an import that rejected rows, a download button gives them as CSV.

The Imports page. History lists store-pages.csv, imported into landing_page to create and update, which finished with rows rejected: 3 created and 1 rejected. Mapping templates starts below it.

Engine API v0.62.0

Shell
curl http://localhost:3001/api/admin/imports/$JOB \
-H "Authorization: Bearer $TOKEN"

Within a moment the job shows "status": "completed" and "inserted_rows": 1. GET .../imports/$JOB/rows lists the row with "status": "inserted" and its entry_id.

5. Roll it back.

Console v0.28.0

Choose the roll back button on the import's line in History. The dialog says how many entries it deletes, and that entries it updated keep the imported values. Choose Roll back. The outcome then reads Rolled back.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/imports/$JOB/rollback \
-H "Authorization: Bearer $TOKEN"
JSON
{ "removed": 1, "status": "rolled_back" }
source_formatWhat it reads
csvA header row, then one row per entry.
jsonAn array of objects, a single object, or a file from data export.
ndjsonOne object per line. A line that is not an object is rejected in its place.
yamlA list of maps, a single map, or a file from data export.
xlsxAn Excel workbook. The first sheet, or the one sheet names, with a header row.

A workbook's cells come back as the sheet shows them. A header cell left empty is named by its column letter, such as C, and empty rows are skipped. Name another sheet with "sheet": "Products" beside file_data. The preview of a workbook lists every sheet it holds under sheets, so you can pick another one.

Leave source_format out and it is detected from the file name, the URL path, the response content type, and then the first bytes.

A data export file imports as it is. Each entry becomes a row with its fields plus schema, slug, title, status, id, published_at, created_at and updated_at. When the file holds several content types, only the rows of content_type are imported.

  • 100,000 rows per import. Split a larger file into several imports.
  • 50 MiB per file, 52,428,800 bytes, uploaded or read from source_url. A file over 50 MiB lists what each case answers.
  • A CSV file or a workbook sheet is read up to 1,024 columns and 5,000,000 cells, its width times its rows. A wider or larger file answers 400 before any row is imported. In a workbook, empty cells after a row's last value do not count toward its width. JSON, NDJSON and YAML rows hold only their own keys, so the size limit bounds them. The 400 for a file that is too wide carries the code bulk_import.too_many_columns, and one with too many cells bulk_import.too_many_cells, beside the message. Every other parse failure carries bad_request.
  • A source_url must be an absolute http or https address. Private, loopback and link-local addresses are refused, after a redirect too. The fetch gives up after 60 seconds and follows at most three redirects. The job keeps the address without its query string, so a signed link's signature is not stored.
  • An import for any tenant but the default one holds a database connection of its own while it runs. On an install whose DATABASE_MAX_CONNECTIONS is below 4 (the default is 25), such an import answers 409 and nothing is imported. A running import that cannot confirm its tenant still exists ends failed with the import could not confirm its tenant.

An uploaded file travels base64-encoded inside the request, so POST /api/admin/imports, /api/admin/imports/validate and /api/admin/imports/preview accept a request of up to 70,953,644 bytes: a 50 MiB file once encoded, plus 1 MiB for the rest of the body. MAX_BODY_BYTES and MAX_JSON_BODY_BYTES do not change that figure. The engine checks the request's size before the import reads any of it. A file of 50.75 MiB or more always makes the request too large.

The fileStatusMessage
Uploaded, in a request over 70,953,644 bytes413Request body exceeds the 70953644 byte limit.
Uploaded, over 50 MiB once decoded, in a request of 70,953,644 bytes or less413decoded file exceeds maximum size of 52428800 bytes
Uploaded in a chunked request, without Content-Length, over 70,953,644 bytes413request body too large
Read from source_url, over 50 MiB422the file is larger than 52428800 bytes

Each 413 carries the code payload_too_large. Nothing is imported. Split the file and import the parts.

Each entry in field_mappings maps one source column to one target:

KeyMeaning
source_fieldThe column in the file. Required.
target_fieldA field of the content type, or entry.slug, entry.title or entry.status. Required.
data_typeConverts the value: string (or text), number, integer (or int), float (or decimal), boolean (or bool), json.
default_valueUsed when the row has no value.
requiredRejects a row with no value.
transformtrim, lowercase or uppercase on every install. date, split or lookup with content-pro.
transform_optionsThe settings of a date, split or lookup transform, below.
  • entry.status takes draft, published or archived. Without it, new entries are drafts, and the Content API serves a draft only to a caller who may read drafts, as the data model page explains.
  • A missing title is taken from a title field, then from the slug.
  • A missing slug is made from the title, with a short suffix when that slug is taken.
  • Every row is checked against the content type's rules.

Parse dates, split lists and look values up

Link to the section Parse dates, split lists and look values up

With content-pro, three more transforms reshape a value before it is stored:

transformtransform_optionsWhat it does
datelayout, the format of the cell, and output_layout, the format to store, RFC 3339 when empty. Both are written as the reference time 2006-01-02 15:04:05."layout": "02/01/2006" reads 31/12/2026.
splitseparator, at most 16 bytes.Turns red; green into a list, each part trimmed and empty ones dropped. Each part takes the mapping's data_type.
lookupmap, up to 1,000 pairs, and an optional default.Replaces a value with the one the map gives it. A value the map lacks takes default, or rejects the row when there is none.
JSON
{"source_field": "Country", "target_field": "region", "transform": "lookup",
"transform_options": {"map": {"FR": "eu", "DE": "eu", "US": "na"}, "default": "other"}}

An unknown transform answers 400. A request that names a paid transform without content-pro answers 402 naming feature:content-pro.

With content-pro, a tenant saves its mappings under a name, with the content type, the key field and the mode. This saves the mapping of the posts.csv file above.

Console v0.28.0

  1. Open Insight > Imports. Under Mapping templates, choose New template.
  2. Enter weekly-posts in Name and pick post in Content type.
  3. Under When an entry already exists, pick Create and update, then Entry slug in Key field.
  4. Enter title in Column in the file and pick title in Field. Choose Add column, enter body and pick body.
  5. Choose Create.

The page confirms Created weekly-posts, and the list shows the template with its content type, its columns and Update it, key entry.slug. To use it, pick it in Mapping template on the wizard's first step. The mapping step then says Mapped from the template weekly-posts.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/imports/templates \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "weekly-posts", "content_type": "post", "upsert_key": "entry.slug", "mode": "upsert", "field_mappings": [{"source_field": "title", "target_field": "title"}, {"source_field": "body", "target_field": "body"}]}'

The answer is 201 with the template. An import or a dry run then names it with "template_id" and may leave out content_type and field_mappings. What the request leaves out comes from the template, and the request's own field_mappings win when it sends them.

A saved template keeps working after the license lapses, and listing, reading and deleting templates stay free. Saving or changing one needs content-pro, and a name already in use in the tenant answers 409.

upsert_key names the field that finds an existing entry: entry.slug or a field of the content type. mode says what happens when a row matches:

modeA row that matches an existing entry
createIs skipped with the reason exists. Without a key, every row is created.
upsertUpdates that entry. Fields the row does not name keep their values. Needs a key.

With a key and no mode, the import is an upsert.

  • "dry_run": true on POST /api/admin/imports, or POST /api/admin/imports/validate with the same body, checks every row and writes nothing. Validate answers each rejected row with a code: mapping_error, validation_error or parse_error.
  • A job moves through pending and running and ends as completed, completed_with_errors, failed, canceled or rolled_back. POST .../cancel stops one that has not finished and answers {"status": "canceling"}.
  • POST .../rollback deletes the entries a completed or completed_with_errors job created. Entries it updated keep the imported values.
  • GET .../rejected downloads the rejected rows as <source>-rejected.csv: row number, error code and reason, then the row's columns.

Bulk import has no settings of its own. It runs on every install. If you set LYEVE_PLUGINS to choose which features start, include bulk-import in it. See licensing and tiers.

Every route takes an admin or super_admin and a signed-in session. An admin token cannot call them. {id} is the job id.

Import routes
MethodPathResult
POST/api/admin/importsStarts an import. 201.
GET/api/admin/importsYour tenant's jobs, as {"jobs", "total_count", "offset", "limit"}. limit is 50 by default.
GET/api/admin/imports/{id}One job, with its mappings.
GET/api/admin/imports/{id}/rowsEach row's outcome, paginated. Filter with ?status=errored, inserted, updated or skipped.
GET/api/admin/imports/{id}/rejectedRejected rows as CSV.
POST/api/admin/imports/{id}/cancelStops a job that has not finished.
POST/api/admin/imports/{id}/rollbackDeletes the entries the job created and marks it rolled_back.
POST/api/admin/imports/validateDry run. Writes nothing.
POST/api/admin/imports/previewDescribes a file, with sheets for a workbook. Writes nothing.
GET/api/admin/imports/templatesYour tenant's mapping templates, with licensed.
POST/api/admin/imports/templatesSave a template: name, field_mappings, and optionally content_type, upsert_key and mode. Needs content-pro.
GET/api/admin/imports/templates/{templateID}One template.
PUT/api/admin/imports/templates/{templateID}Replace a template. Needs content-pro.
DELETE/api/admin/imports/templates/{templateID}Delete a template.
Every error these routes return
StatusMessage
400invalid JSON
400file_data or source_url is required, send file_data or source_url, not both
400file_data is not valid base64
400failed to parse file: ..., including row count exceeds maximum of 100000 rows, the file has more than 1024 columns, the sheet holds more than 5000000 cells and the workbook has no sheet named "<name>"
400source_field '<x>' not found in data. Available: ...
400field_mappings or template_id is required
400field_mappings[<column>]: transform must be one of trim, lowercase, uppercase, date, split or lookup, or a message naming the missing option, such as the date transform needs transform_options.layout
402payment_required, naming feature:content-pro, for a paid transform or a template write
404mapping template not found
409a mapping template with that name already exists
422template_id names no mapping template of this tenant
400dry-run jobs cannot be rolled back
404import job not found
409job is already <status> on cancel
409only completed jobs can be rolled back (current status: <status>)
409imports for a tenant need DATABASE_MAX_CONNECTIONS of at least 4
413Request body exceeds the 70953644 byte limit., for a request over 70,953,644 bytes
413decoded file exceeds maximum size of 52428800 bytes
413request body too large, for a chunked request that runs past 70,953,644 bytes
422content_type is not a defined content schema
422target_field is not a field of this content type: <field>
422an upsert needs upsert_key, the field that finds the entry to update
422upsert_key must be entry.slug or a field of this content type
422source_url must be an absolute http or https address
422the address could not be reached; private and internal addresses are refused, the address took too long to answer, the address answered <code> <text>, the file is larger than 52428800 bytes