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:
| v1 | v2 | |
|---|---|---|
| Target list | An existing list, by list_id | A list by list_id, or by name, created if not found |
| Folder | Not set | folder, such as Customers/Finland, created if not found |
| Data | CSV, raw or Base64-encoded, or a JSON array | A CSV or XLS file, Base64-encoded |
| Extra options | disable_cem_events and use_duplicates, CSV only | None |
| Response | null for CSV, true for JSON | The list ID |
| Missing email or SMS column | Found only when the import runs | Rejected 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
-
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.
-
Wait for it to finish
Call
getImportStatuswith the list ID, for example every few seconds. It returns0while the import is waiting, then the number of lines processed so far, and-1when the import has finished. -
Read the results
getImportLogreturns 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.