Factuarea APIDevelopers

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}.

EntityPath segmentRequired mapping targetsScopes
Warehouseswarehousescode, name, address_line1, city, postal_codewarehouses:write (preview, import) · warehouses:read (the rest)
Initial stock per warehousewarehouse-stockwarehouse_code, quantity and product_sku or product_external_idwarehouses:write · warehouses:read
Sales orderssales-ordersdocument_number, date, buyer_name, line_description, line_quantity, line_pricesales_orders:write · sales_orders:read
Purchase orderspurchase-ordersdocument_number, supplier_tax_id, line_sku, line_quantitypurchase_orders:write · purchase_orders:read

For every segment {entity} above, the five operations are:

OperationMethod and pathPurpose
TemplateGET /{entity}/import/templateDownload the file layout the importer accepts.
PreviewPOST /{entity}/import/previewReport what the execution would do, without writing.
ImportPOST /{entity}/importExecute the import. Irreversible.
RetrieveGET /{entity}/imports/{id}Read the erp_import object of an import.
ErrorsGET /{entity}/imports/{id}/errors.csvDownload 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 example mapping[Number]=document_number. It must include the required targets of the entity listed above.
  • auto_create_series: only for sales orders and purchase orders. When true, 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:

FieldMeaning
total_rows, added_count, skipped_count, failed_countRows read, documents that would be created, skipped and rejected.
itemsOne 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.
errorsRejected rows with row (the header is row 1), param, code and a message in Spanish.
warningsNon-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. A supplier_tax_id of a contact without the supplier role fails with SUPPLIER_ROLE_MISSING, and one of no contact of the company with FK_NOT_FOUND; in the import, both carry params.tax_id with 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 is VALUE_TOO_LONG with params.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), is INVALID_RANGE, and a text longer than its limit is VALUE_TOO_LONG; the rest of the file is imported.
  • Keys: the key of the preview and the group_key of the results hold up to 240 characters. A longer key is published as its first 199 characters, ~ and the sha1 of 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.

StatusMeaning
201The import ran in the request (up to 200 rows). The body is the erp_import object with its final counters.
202The 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.

FieldMeaning
id, object, entity_typeThe import identifier, erp_import, and one of warehouses, warehouse_stock, sales_orders, purchase_orders.
statusqueued, running, completed, partial or failed.
source_filenameThe name of the uploaded file.
total_rows, added_count, updated_count, skipped_count, failed_count, warnings_count, unprocessed_countThe seven counters.
outcome_kindchanges_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_reasonsSkipped rows counted by reason, such as already_exists or duplicate_in_file.
first_diagnosticsUp to 20 grouped diagnostics with code, field, severity, message, count and first_row.
outcomes, outcomes_truncatedUp to 500 row outcomes (row_number, result, action, reason, group_key, target_uuid, errors) and whether more were left out.
error_report_urlThe path of the CSV report, when the import has one.
failure_reason, created_at, started_at, finished_atFailure 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 429 with import_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 empty param and the row reason plan_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 answers 402.
  • File size. A request body above 10 MB answers 413 with payload_too_large; a file above 10 MB that fits the envelope answers 422 on the file parameter.

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.

ModuleScopesPlans
Warehouses (also initial stock)warehouses:read, warehouses:writeAvanzado (integral), Enterprise
Sales orderssales_orders:read, sales_orders:writeAvanzado (integral), Enterprise
Purchase orderspurchase_orders:read, purchase_orders:writeAvanzado (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.

EntityPreviewImportRetrieveErrors
Warehousespreview_warehouses_importimport_warehousesget_warehouse_importdownload_warehouse_import_errors
Initial stockpreview_warehouse_stock_importimport_warehouse_stockget_warehouse_stock_importdownload_warehouse_stock_import_errors
Sales orderspreview_sales_orders_importimport_sales_ordersget_sales_order_importdownload_sales_order_import_errors
Purchase orderspreview_purchase_orders_importimport_purchase_ordersget_purchase_order_importdownload_purchase_order_import_errors
  • The preview and import tools take file_base64 (the file encoded in base64, up to 10 MB decoded), filename, mapping and, only for orders, auto_create_series. The import tools also accept idempotency_key; reuse the same key when you retry.
  • The retrieve and errors tools take the id of the import. The errors tool returns the same bytes as the HTTP download, as file_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 422 with business_rule_violation and subcode media_too_large. The other codes on this page keep their status and code over MCP.

On this page

Need a hand?Contact support