Skip to main content

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

  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'

Request

Responses

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