Pre Import CSV data
Changed onThe 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_type to 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 records
- files[client] — client records
- files[product] — product records
- files[payment] — payment records
- files[vendor] — vendor records
- files[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/import call.
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
- Base URLhttps://demo.invoiceninja.com
- Authnone declared. Required headers: X-API-TOKEN, X-Requested-With
- TypeScriptA function with typed inputs. Its response is checked against the schema.
Query parameters
Includes child relationships in the response, format is comma separated. Check each model for the list of associated includes
Headers
The API token to be used for authentication
Used to send the XMLHttpRequest header
Request body multipart/form-data
Example request
{
"import_type": "invoice"
}Response
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/import when 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 available array representing the best-guess system field for that column, or null when no match could be determined.
Example response
{
"hash": "MvKeSwMnhAfgkzdYKgxM5ummxGbLIdNm"
}Changes
- breaking
added the new required request property
- breaking
the request's body type changed from
stringtoobject, and format frombinaryto no format - info
added the new optional request property
- info
added the new optional request property
- info
added the new optional request property
- info
added the new optional request property
- info
added the new optional request property
- info
added the new optional request property
- info
added the media type
application/jsonfor the response with the status
- breaking
- breaking
the response's body type changed from no type to
objectfor status - info
added the optional property
to the response with the status - info
added the optional property
to the response with the status
- breaking