Pre Import CSV data
POST/api/v1/preimport
The preimport endpoint is the first step when importing CSV data into Invoice Ninja. It validates your file(s) and returns the column headers found in each CSV, allowing you to map them to system fields before performing the actual import.
How it works
- Set
import_typeto indicate the entity type (e.g.invoice,quote,client,product,payment,vendor,expense). - Attach one or more CSV files using the
files[]parameter, keyed by entity type:files[invoice]— invoice recordsfiles[client]— client recordsfiles[product]— product recordsfiles[payment]— payment recordsfiles[vendor]— vendor recordsfiles[expense]— expense records
- The response returns the detected column headers for each uploaded file so you can build a field mapping for the subsequent
/api/v1/importcall.
You may upload multiple entity files in a single request. Only include the entity types relevant to your import.
Example
curl -X POST 'https://invoiceninja.com/api/v1/preimport' \
-H 'X-API-TOKEN: YOUR_API_TOKEN_HERE' \
-H 'Accept: application/json' \
-F 'import_type=invoice' \
-F 'files[invoice]=@invoices.csv' \
-F 'files[client]=@clients.csv'
Request
Responses
- 200
- 401
- 403
- 422
- default
Returns a hash identifying the uploaded file(s) and a mappings object for each entity type submitted.
- hash — A unique reference to the uploaded file(s). Pass this to
/api/v1/importwhen executing the import. - mappings — An object keyed by entity type (e.g.
invoice,client). Each entity contains:- available — The system fields that can be mapped to for this entity (e.g.
invoice.number,client.name,item.cost). - headers — A two-dimensional array. The first element contains the column headers detected from your CSV. The second element contains a sample data row, useful for previewing values during field mapping.
- hints — An array of suggested mappings, one per CSV column. Each value is an index into the
availablearray representing the best-guess system field for that column, ornullwhen no match could be determined.
- available — The system fields that can be mapped to for this entity (e.g.
Response Headers
X-MINIMUM-CLIENT-VERSION
The API version
X-RateLimit-Remaining
The number of requests left for the time window.
X-RateLimit-Limit
The total number of requests in a given time window.
Authentication error
Authorization error
Validation error
Unexpected Error