imports

Pre Import CSV data

Changed on

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

  1. Set import_type to indicate the entity type (e.g. invoice, quote, client, product, payment, vendor, expense).
  2. 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
  3. 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'
post/api/v1/preimport

Request

Query parameters

includestring
Example:first_load

Includes child relationships in the response, format is comma separated. Check each model for the list of associated includes

Headers

X-API-TOKENstring required
Example:TOKEN

The API token to be used for authentication

X-Requested-Withstring required
Example:XMLHttpRequest

Used to send the XMLHttpRequest header

Request body multipart/form-data

import_typestring required

The type of import being performed

files[invoice]string binary

CSV file for invoices

files[client]string binary

CSV file for clients

files[product]string binary

CSV file for products

files[payment]string binary

CSV file for payments

files[vendor]string binary

CSV file for vendors

files[expense]string binary

CSV file for expenses

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

Unique reference to the uploaded file(s), required for the subsequent import call.

mappingsobject

An object keyed by entity type containing field mapping data for each uploaded CSV.

Example response

{
  "hash": "MvKeSwMnhAfgkzdYKgxM5ummxGbLIdNm"
}

Changes

    • breaking

      added the new required request property

    • breaking

      the request's body type changed from string to object, and format from binary to 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/json for the response with the status

    • breaking

      the response's body type changed from no type to object for status

    • info

      added the optional property to the response with the status

    • info

      added the optional property to the response with the status