ERP imports
Import warehouses, initial stock per warehouse, sales orders and purchase orders from a file, with a preview, a trackable import and a CSV report of rejected rows.
Four ERP entities can be loaded from a spreadsheet through the public API: warehouses, initial stock per warehouse, sales orders and purchase orders. All four follow the same sequence: download the template, preview the file, execute the import, then read it and download the report of rejected rows. Contacts have their own importer, described in Contact imports.
The four entities and their operations
Each entity has five operations, twenty in total. The path prefix is /v1/companies/{company}.
| Entity | Path segment | Required mapping targets | Scopes |
|---|---|---|---|
| Warehouses | warehouses | code, name, address_line1, city, postal_code | warehouses:write (preview, import) · warehouses:read (the rest) |
| Initial stock per warehouse | warehouse-stock | warehouse_code, quantity and product_sku or product_external_id | warehouses:write · warehouses:read |
| Sales orders | sales-orders | document_number, date, buyer_name, line_description, line_quantity, line_price | sales_orders:write · sales_orders:read |
| Purchase orders | purchase-orders | document_number, supplier_tax_id, line_sku, line_quantity | purchase_orders:write · purchase_orders:read |
For every segment {entity} above, the five operations are:
| Operation | Method and path | Purpose |
|---|---|---|
| Template | GET /{entity}/import/template | Download the file layout the importer accepts. |
| Preview | POST /{entity}/import/preview | Report what the execution would do, without writing. |
| Import | POST /{entity}/import | Execute the import. Irreversible. |
| Retrieve | GET /{entity}/imports/{id} | Read the erp_import object of an import. |
| Errors | GET /{entity}/imports/{id}/errors.csv | Download the CSV report of the rows that were not applied. |
Initial stock per warehouse is exposed under the warehouse-stock segment and listed in the API Reference with the Warehouses operations. It creates one opening movement per balance: repeating the same file neither duplicates nor adds quantity, and a product that does not track stock is rejected with STOCK_NOT_TRACKED.
Download the template
GET /v1/companies/{company}/{entity}/import/template returns the template generated from the importer columns. It carries no company data and requires the read scope of the entity.
?format=csv(default): a UTF-8 CSV with only the headers.?format=xlsx: a workbook with the Data, Instructions, Examples and Allowed values sheets.
Any other format is 422 invalid_param_value with param format. A credential without the read scope of the entity is 403 insufficient_scope before the format is read. The template of the contacts import takes the same parameter.
Fill in one row per line (one row per warehouse or per balance; one or more rows per order, grouped by document_number) and keep the headers, or map your own headers in the next step.
Map the columns and preview
Send the file as multipart/form-data to POST /v1/companies/{company}/{entity}/import/preview. The file accepts CSV, TXT, XLSX, XLS or ODS up to 10 MB. The body has:
file: the spreadsheet.mapping: file column header → target field, for examplemapping[Number]=document_number. It must include the required targets of the entity listed above.auto_create_series: only for sales orders and purchase orders. Whentrue, series codes that do not exist yet are created automatically.
curl -X POST https://api.factuarea.com/v1/companies/$COMPANY_ID/sales-orders/import/preview \
-H "Authorization: Bearer $FACTUAREA_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F "file=@sales-orders.csv" \
-F "mapping[Number]=document_number" \
-F "mapping[Date]=date" \
-F "mapping[Customer]=buyer_name" \
-F "mapping[Concept]=line_description" \
-F "mapping[Quantity]=line_quantity" \
-F "mapping[Price]=line_price"The mapping is validated before anything is registered. A value that is not a target field of the entity, a negative one, or one longer than 255 characters is 422 with param mapping.<header>. Two file columns mapped to the same field, a required field left unmapped, or an empty or repeated header is 422 business_rule_violation with subcode invalid_column_mapping and param mapping. A header named with a whole number (-1, 0, 2024) that the file does not have is 422 mapping_header_not_found; when the file has it, the column is mapped. A rejected mapping registers no import and queues no work.
The preview answers 200 and writes nothing. Its data object reports exactly what the execution would do with the same file and mapping:
| Field | Meaning |
|---|---|
total_rows, added_count, skipped_count, failed_count | Rows read, documents that would be created, skipped and rejected. |
items | One entry per document or record: row, rows, key, action (create or skip), reason for a skip, target_id when it matches an existing record, header and lines. For orders, contact_will_be_created and series_will_be_created announce side effects. |
errors | Rejected rows with row (the header is row 1), param, code and a message in Spanish. |
warnings | Non-blocking notices. |
The preview and the execution apply the same rules as the application importer, so the counts the preview announces are the ones the execution applies. Entity notes:
- Warehouses: a missing province is deduced from the postal code; a code that is already in use is skipped.
- Initial stock: a balance that already has its opening is skipped.
- Purchase orders: a row that names a supplier or a product the company does not have fails with its
param. Asupplier_tax_idof a contact without the supplier role fails withSUPPLIER_ROLE_MISSING, and one of no contact of the company withFK_NOT_FOUND; in the import, both carryparams.tax_idwith the tax ID of the file. - Sales orders: when the plan of the company has a monthly limit of sales orders, the orders beyond it fail row by row, see Plan allowances. A row whose buyer, tax ID or address is longer than its column is marked
VALUE_TOO_LONG. - Rejected rows: in the imports of warehouses and of warehouse stock each rejected row carries
column, the header of the file that is mapped to the rejected field, and a text that is too long isVALUE_TOO_LONGwithparams.max. A purchase-order row with a quantity or a cost of more than four decimals, or a VAT, withholding or surcharge that is negative, has more than two decimals or exceeds 100 (the withholding is read as a magnitude), isINVALID_RANGE, and a text longer than its limit isVALUE_TOO_LONG; the rest of the file is imported. - Keys: the
keyof the preview and thegroup_keyof the results hold up to 240 characters. A longer key is published as its first 199 characters,~and thesha1of the whole key.
Execute the import
Send the reviewed file and the same mapping to POST /v1/companies/{company}/{entity}/import, with a new Idempotency-Key.
| Status | Meaning |
|---|---|
201 | The import ran in the request (up to 200 rows). The body is the erp_import object with its final counters. |
202 | The import was queued (more than 200 rows). The body is the erp_import object with status queued. |
Both answers carry a Location header that points to …/{entity}/imports/{id}. Acceptance is not proof that every row completed: follow a queued import with the retrieve operation. Invalid rows go to the error report and the batch goes on.
Idempotency and concurrency
The four executions are irreversible and require the Idempotency-Key header. Without it the API answers 422 with idempotency_key_required before any business logic runs. Repeating a call with the same key and body returns the same response and the same Location, with Idempotent-Replayed: true, and creates no rows. Reusing a key with a different body returns 422 idempotency_key_reused. The contract also declares the header on the preview, so send a key there too.
Only one import per company and entity runs at a time. While another import of the same company and entity is queued or running, a new execution answers 409 with import_in_progress. Nothing is processed, no row allowance is spent and no import is registered. Wait for the running import to end, then send the same file again with a new Idempotency-Key. Imports of other entities, and previews, are not blocked.
Read the import
GET /v1/companies/{company}/{entity}/imports/{id} takes the id returned by the execution and answers with the erp_import object. It requires the read scope of the entity. An unknown import, one that belongs to another company and one that belongs to another entity return the same 404 with import_not_found.
| Field | Meaning |
|---|---|
id, object, entity_type | The import identifier, erp_import, and one of warehouses, warehouse_stock, sales_orders, purchase_orders. |
status | queued, running, completed, partial or failed. |
source_filename | The name of the uploaded file. |
total_rows, added_count, updated_count, skipped_count, failed_count, warnings_count, unprocessed_count | The seven counters. |
outcome_kind | changes_applied, nothing_changed, partial or failed; null while queued or running. nothing_changed finished without creating anything, so do not present it as a success. |
skip_reasons | Skipped rows counted by reason, such as already_exists or duplicate_in_file. |
first_diagnostics | Up to 20 grouped diagnostics with code, field, severity, message, count and first_row. |
outcomes, outcomes_truncated | Up to 500 row outcomes (row_number, result, action, reason, group_key, target_uuid, errors) and whether more were left out. |
error_report_url | The path of the CSV report, when the import has one. |
failure_reason, created_at, started_at, finished_at | Failure cause and timestamps. |
{
"data": {
"id": "0199f6a0-3c10-7a01-8b01-000000000301",
"object": "erp_import",
"entity_type": "sales_orders",
"status": "partial",
"source_filename": "sales-orders-october.csv",
"total_rows": 3,
"added_count": 1,
"updated_count": 0,
"skipped_count": 1,
"failed_count": 1,
"warnings_count": 0,
"unprocessed_count": 0,
"outcome_kind": "partial",
"skip_reasons": { "already_exists": 1 },
"outcomes_truncated": false,
"error_report_url": "/v1/companies/0193f1a0-5c2e-7b41-8d06-9a1e2f3c4d5e/sales-orders/imports/0199f6a0-3c10-7a01-8b01-000000000301/errors.csv"
}
}Download the rejected rows
GET /v1/companies/{company}/{entity}/imports/{id}/errors.csv returns a UTF-8 CSV with the original row number, field, code and message of each row that was not applied. It requires the read scope of the entity. A missing or unavailable report, and an import of another company or entity, return 404 with import_not_found. Correct the rows in the original file and import it again with a new Idempotency-Key.
Plan allowances
- Monthly row allowance. Executions draw on the plan monthly import row allowance, the same one the other importers use. When no allowance is left the API answers
429withimport_row_quota_exceeded. This allowance is separate from uploaded bytes and from request rate limits. - Monthly sales-order limit. When the plan of the company has a monthly limit of sales orders, the limit is applied row by row: orders over it fail with
sales_orders_monthly_limit_exceeded, an emptyparamand the row reasonplan_limit_reached, while the rest of the file goes on. The preview announces the same rejections. The CSV report carries the same code for those rows. The request itself never answers402. - File size. A request body above 10 MB answers
413withpayload_too_large; a file above 10 MB that fits the envelope answers422on thefileparameter.
Scopes and plans
The module of each entity decides which plans can issue its scopes. A key requests warehouses:*, sales_orders:* or purchase_orders:* when it is created; if the plan does not include the module, creation answers 422 with scope_not_allowed_by_plan. Without the scope, the operation answers 403 with insufficient_scope.
| Module | Scopes | Plans |
|---|---|---|
| Warehouses (also initial stock) | warehouses:read, warehouses:write | Avanzado (integral), Enterprise |
| Sales orders | sales_orders:read, sales_orders:write | Avanzado (integral), Enterprise |
| Purchase orders | purchase_orders:read, purchase_orders:write | Avanzado (integral), Enterprise |
The preview and the execution need the write scope; the template, the retrieve operation and the errors need the read scope. The public API itself requires a plan with API access.
MCP tools
The MCP server mirrors the preview, execution, retrieve and errors operations with four tools per entity. The template has no tool: it is a REST download.
| Entity | Preview | Import | Retrieve | Errors |
|---|---|---|---|---|
| Warehouses | preview_warehouses_import | import_warehouses | get_warehouse_import | download_warehouse_import_errors |
| Initial stock | preview_warehouse_stock_import | import_warehouse_stock | get_warehouse_stock_import | download_warehouse_stock_import_errors |
| Sales orders | preview_sales_orders_import | import_sales_orders | get_sales_order_import | download_sales_order_import_errors |
| Purchase orders | preview_purchase_orders_import | import_purchase_orders | get_purchase_order_import | download_purchase_order_import_errors |
- The preview and import tools take
file_base64(the file encoded in base64, up to 10 MB decoded),filename,mappingand, only for orders,auto_create_series. The import tools also acceptidempotency_key; reuse the same key when you retry. - The retrieve and errors tools take the
idof the import. The errors tool returns the same bytes as the HTTP download, asfile_base64. - Each tool needs the same scope as its REST operation and is listed only for credentials that carry it.
- More than 10 MB decoded answers
422withbusiness_rule_violationandsubcodemedia_too_large. The other codes on this page keep their status andcodeover MCP.