Aller au contenu principal

CSV formats

CSV imports and exports are built on pkg/csvx (see libraries): columns are declared once per type and drive parsing and writing. Implemented today: members (import, export) and inventory (items, consumables, locations). Other services have no CSV yet.

Common rules​

Reading (imports)​

RuleBehaviour
Uploadmultipart/form-data, field file; body size capped by the service (see each format)
EncodingUTF-8; a leading BOM is skipped
Separator, or ;, detected on the first line (more ; than , means ;)
Quotingstandard CSV double quotes; rows may have a variable number of fields; leading spaces trimmed
Headerrequired (line 1); names trimmed and lower-cased, so matching is case-insensitive; order free; unknown columns ignored
Cellstrimmed; an empty cell is treated as absent (default value, or required error)
Listsmultiple values in one cell are separated by |; empty items dropped
Row limitabove the limit the whole file is rejected (400 invalid_csv)
Dry rundry_run=true as query parameter or form field: validate only, write nothing

Validation is all-or-nothing: every row is parsed and validated first. If any error exists, the response is 422 with every error, valid: 0, and nothing is written. Otherwise the rows are written one by one (unless dry run) and each line gets its own outcome; a failure while writing one line (e.g. an unavailable provider) does not stop the others and is not rolled back.

Errors use csvx.LineError; line numbers are 1-based physical lines of the file (header = line 1):

{"line": 3, "column": "personal_email", "message": "email"}
Sourcecolumnmessage
Missing required headercolumn name (line 1)missing column; no row is parsed
Empty required cellcolumn namerequired
Cell parsercolumn nameparser message (e.g. unknown status, invalid number)
Domain validationdomain field name (may differ from the CSV column, e.g. site_ids, site_id, purchase.price)validation tag (required, email, max, oneof…)
Other failures (inventory)emptyproblem code (e.g. forbidden)
Malformed CSV (bad quoting)emptyencoding/csv error text

Import response (200 or 422):

{"dry_run": false, "valid": 2, "errors": [], "lines": [{"line": 2, "...": "per format"}]}

lines is only present after a real (non dry run) import with no errors.

Writing (exports)​

RuleBehaviour
Response200, Content-Type: text/csv; charset=utf-8, Content-Disposition: attachment
EncodingUTF-8 with BOM (spreadsheet compatibility)
Separator,, LF line endings, standard quoting
Listsjoined with |
Formula injectiona cell starting with =, +, -, @, tab or CR is prefixed with ' (so +33 6… is exported as '+33 6…)
Auditevery export is an audited read
Filtersthe list filters of the resource apply; results are limited to the caller's authz scope

Members​

Import​

POST /v1/members/import — permission members.member.create on the whole member collection (a site-scoped grant is not enough). Limits: 1 MiB request body (400 invalid_file above), 500 data rows.

ColumnRequiredFormat
first_nameyestext, 1–64 characters
last_nameyestext, 1–64 characters
personal_emailnobare e-mail address (no display name), ≤ 254 characters
phonenooptional +, then 6–24 characters among digits, space, ( ) . -
polesno| list among tech, bike, textile, mechanics, printing_3d, communication
sitenoone site ID matching ^[a-z0-9][a-z0-9_-]{0,63}$
statusnokey of an existing status; default MEMBER_DEFAULT_STATUS (active)

Not importable: display name (defaults to first_name last_name), birth date, pronouns, locale (fr). Parser messages: unknown pole (allowed: …), invalid site identifier, unknown status.

Each valid line is then created like POST /v1/members (Workspace + Keycloak provisioning, see members), sequentially. Line outcome:

FieldMeaning
lineline number
member_idmember created
provisioning_id + errorprovisioning failed at a step (workspace_failed, keycloak_failed, keycloak_link_failed, store_failed); retry through POST /v1/members/provisionings/:id/retry
error aloneproblem code (e.g. workspace_email_unavailable, unavailable)

Initial Workspace passwords are not returned by the import (only by the single create).

Line numbers

The members handler recomputes the line of each valid row assuming one record per line from line 2. After a blank line or a quoted cell spanning several lines, validation errors and outcomes may point to the wrong line (errors raised by csvx itself are exact). The inventory imports keep exact line numbers.

first_name;last_name;personal_email;phone;poles;site;status
Ada;Lovelace;ada@example.org;+33 6 12 34 56 78;tech|printing_3d;paris;active
Jean;Dupont;;;bike;strasbourg;

Export​

GET /v1/members/export.csv → members.csv. Permission members.member.export on the whole collection; audited as members.member.export. Filters: q, status, pole, site, include_deleted (also needs members.member.delete). Deleted and erased members are excluded by default. The file is built in memory (no pagination). Private fields are included.

ColumnContent
idmember ID (Keycloak ID)
first_name, last_name, display_namenames
workspace_emailWorkspace address
personal_email, phoneprivate fields (decrypted)
poles| list
sitesite IDs, | list
statusstatus key
id,first_name,last_name,display_name,workspace_email,personal_email,phone,poles,site,status
6f1c…,Ada,Lovelace,Ada Lovelace,ada.lovelace@atelier-maker.fr,ada@example.org,'+33 6 12 34 56 78,tech|printing_3d,paris,active

Inventory​

Common to the three imports: 5 MiB request body, 5000 data rows, errors sorted by line. Line outcome: line, id, short_code (items), status (created, or exists for locations), error (problem code). Exports are streamed row by row (common writing rules above). Upload errors: missing or unreadable file field (or body over 5 MiB) → 400 invalid_file; unparsable file or more than 5000 rows → 400 invalid_csv. Formats are also described in the API reference.

Items and consumables import​

POST /v1/inventory/items/import (tools and machines) and POST /v1/inventory/consumables/import. Each row is checked with inventory.item.create on the new item (site parent). Common columns:

ColumnRequiredFormat
nameyestext, ≤ 200 characters
descriptionno≤ 4000 characters
category, brand, model, serialno≤ 64, 100, 100, 100 characters
siteyessite ID ^[a-z0-9][a-z0-9_-]{0,63}$
locationnolocation ID, or name path in the site (Salle A/Armoire 1, case and accent insensitive); unresolved → location / not_found
project_idno^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$
tagsno| list, ≤ 30 tags of ≤ 40 characters (normalised: lower case, no accents, words joined by -)
supplierno≤ 200 characters
purchase_pricenodecimal ≥ 0, . or , as decimal mark
purchase_datenoYYYY-MM-DD
custom_fieldsnokey=value|key=value, ≤ 30 pairs, key ≤ 64, value ≤ 500 characters

Items only:

ColumnRequiredFormat
kindnotool (default) or machine
statusnoavailable (default), borrowed, in_maintenance, out_of_service, lost
required_training_type_idsno| list of up to 20 training type IDs

Consumables only (kind is always consumable, status available):

ColumnRequiredFormat
unityespiece, m, g, kg, ml, l, sheet
quantitynodecimal ≥ 0, default 0
low_stock_thresholdnodecimal ≥ 0
unit_costnodecimal ≥ 0
name;site;location;kind;category;tags;purchase_price;purchase_date;custom_fields
Perceuse Bosch;paris;Salle A/Armoire 1;tool;perçage;sans fil|18V;89,90;2025-10-02;voltage=18V
Laser Epilog;paris;Salle B;machine;découpe;;12000;2024-01-15;
name,site,unit,quantity,low_stock_threshold,unit_cost
Contreplaqué 3 mm,paris,sheet,40,10,"4,50"
Filament PLA noir,paris,kg,12,2,22

Items and consumables export​

GET /v1/inventory/items/export.csv (items.csv, tools and machines) and GET /v1/inventory/consumables/export.csv (consumables.csv). Results are limited to the inventory.item.read scope; both audited as inventory.item.export. Filters: q, site, location, kind (must match the export, otherwise 422), status, category, tag, project, low_stock, include_deleted (needs inventory.item.read_all).

Columns: id, short_code, kind, name, description, category, brand, model, serial, site, location (name path), location_id, status, project_id, tags, supplier, purchase_price, purchase_date, custom_fields (keys sorted), then required_training_type_ids (items) or unit, quantity, low_stock_threshold, unit_cost (consumables). Numbers use .. The import ignores the extra columns (id, short_code, location_id…), so an export can be re-imported to create copies.

Locations import​

POST /v1/inventory/locations/import. Permission inventory.location.create per site.

ColumnRequiredFormat
siteyessite ID
pathyesnames from the site root separated by / (Salle A/Armoire 1); each name 1–100 characters
typeyeskey of a location type of the site (defaults: room, furniture, shelf, bin); else type / unknown
descriptionno≤ 1000 characters

Lines are processed in order: the parent of a path must exist or be created by an earlier line (otherwise path / parent_not_found). An existing path (compared case and accent insensitive) is reported exists and left unchanged.

site,path,type,description
paris,Salle A,room,Atelier bois
paris,Salle A/Armoire 1,furniture,
paris,Salle A/Armoire 1/Étagère haute,shelf,Visserie

Locations export​

GET /v1/inventory/locations/export.csv → locations.csv, limited to the inventory.location.read scope, audited as inventory.location.export. Filters: site, parent, under, q. Parents come before children, so the file can be re-imported as is. Columns: id, site, path, type, description, parent_id.

id,site,path,type,description,parent_id
01J…A,paris,Salle A,room,Atelier bois,
01J…B,paris,Salle A/Armoire 1,furniture,,01J…A