Guides

Importing contacts

An import adds many contacts to a mailing list in one request. The import runs in the background, and you follow its progress with the v1 import endpoints, whether you started it with v1 or v2.

Choose v1 or v2

The v2 import/mailinglist takes a CSV or XLS file. It can find the list by name, and creates the list and its folder if they do not exist yet.

The v1 importCSVToMailingList and importJSONToMailingList import CSV or JSON data into a list that already exists. The CSV import can also leave out the LianaAutomation events.

The v2 import and importCSVToMailingList can both replace the current members of the list (truncate), save the values as list-specific properties (use_list_props), and give the contacts a consent (consent_id and consent_lang). The differences are:

v1v2
Target listAn existing list, by list_idA list by list_id, or by name, created if not found
FolderNot setfolder, such as Customers/Finland, created if not found
DataCSV, raw or Base64-encoded, or a JSON arrayA CSV or XLS file, Base64-encoded
Extra optionsdisable_cem_events and use_duplicates, CSV onlyNone
Responsenull for CSV, true for JSONThe list ID
Missing email or SMS columnFound only when the import runsRejected in the response

importJSONToMailingList takes only list_id and the data, and always imports with the default options.

Prepare the data

CSV data uses ; as the field separator and " as the enclosure character, and is encoded in UTF-8 with Unix line endings (\n).

The first row names the columns. One of them must be the email column (email, e-mail, mail, e_mail or @mail) or the sms column. The other columns are property names, matched case-insensitively. A column whose name matches no existing property creates a new one, so check the spelling, and do not use reserved property names.

Blocked addresses

The import checks the email addresses against a blocklist of addresses and domains. If even one address is blocked, nothing is imported. Check the data first with isCSVToMailingListAllowed. It returns true if no address is blocked, and otherwise the blocked addresses as CSV for you to remove.

Follow the import

  1. Start the import

    The request returns before the import is done. An account runs one import at a time, so a new import may have to wait for earlier ones to finish.

  2. Wait for it to finish

    Call getImportStatus with the list ID, for example every few seconds. It returns 0 while the import is waiting, then the number of lines processed so far, and -1 when the import has finished.

  3. Read the results

    getImportLog returns the counts of new, updated, duplicate and rejected records, and the records that were not imported. An empty log means that the import failed before it started, for example because of a blocked address or a missing email or SMS column. The next import to the same list replaces the log.

v2 imports start later

The v2 import runs as a queued background job. Until the job starts, getImportStatus returns -1, the same value as when no import is running, and getImportLog returns the log of the previous import. So -1 right after a v2 import does not mean that it has finished. v1 imports are not affected.

Large imports

An import request fails if the account already has too many imports waiting. Split a large import into batches, for example of 10,000 contacts, and start each batch after the previous one has finished.

Last modified on