Import Contacts via FTP

You can use this request to import contacts via an FTP client.


The Method

API Method
RESTPOSThttp://[Your URL]/api/2.0/imports/ftp
XML-RPCCallImportFtpImports
Your URL is the address of your Everlytic install.

Your method must be structured as follows:

ImportFtpImports(\struct | array $credentials, $mappings, $listIds, $settings) : obj

Parameters

You will need the following parameters before you can use this API request:

PropertyTypeDescriptionRequired
$credentialsStringThe credentials required to log into the FTP server.Yes
$mappingsArrayA list of mappings where the key is the field to map, and the value is the position of the field in the CSV file
E.g. Array(‘email’ => 0, ‘name’ => 2) (email will be the first column in the CSV and name will be the third column in the CSV)
Yes
$listIdsArrayAn array of list IDs to import into.
E.g. Array(1, 2) will import into list 1 and 2 provided they exist.
Yes
$settingsArrayAn array of settings you need for the list.Yes

Properties

When filling out the $credentials and $settings parameters, you will need the following properties:

$credentials

PropertyTypeDescriptionDefaultRequiredRead Only
HostnamestringThe FTP hostname to connect to.emptyYesYes
UsernamestringThe username to use when connecting to the FTP host.emptyYesYes
PasswordstringThe password to use when connecting to the FTP.emptyYesYes
PortstringThe FTP port21YesYes
FilestringThe location of the file on the FTP serveremptyYesYes

$settings

PropertyTypeDescriptionDefaultRequired
Update_duplicatesstringYes/No instruction on whether or not to update duplicates.YesYes
Update_usingstringThe ID to use when updating. Choose between:
none, unique_id, system_id

This field must be used together with custom_key_position
noneYes
Custom_key_positionstringPosition of custom key in fileemptyYes
DelimiterstringThe delimiter used to separate values in the import.
You can choose between 'comma', 'semicolon', 'pipe', 'tab'.
commaYes
Progress_email_addressstringEmail address to send the import report to.emptyYes

Sample Code

Tutorial

The rest of this document describes the example above, step-by-step.

In our Getting Started section we covered the four important components of an API request; URL, method, headers, and body.

RequestStructure

Let's analyse the code sample above to determine where each line fits into this outline.

1. Tell the API Server that you are sending a request

The first two lines in the sample tell the server that you're sending an API request.

<p?<?php

$request = new HttpRequest();

2. Load the Everlytic API

The next line of code tells the server which API URL to access for the request:

$request->setUrl(/api/2.0/imports/sftp');

Your URL is the URL of your Everlytic installation.

3. Method

In this line of code, you tell the API which REST function to use:

$request->setMethod(HTTP_METH_POST);

4. Initiate the Headers

This section of the code opens the headers section and passes the authentication (including your API key).

$request->setHeaders(array(

'content-type' => 'application/json',

'authorization' => 'Basic YWRtaW5pc3RyYXRvcjpqSVYxT=='

));

5. Set the parameters and variables for the call

The following section of code tells the server which parameters and variables to use when importing the contacts in the list using this method.

$request->setBody('{

"credentials": {

"hostname": "127.0.0.1",

"username": "vagrant",

"password": "vagrant",

"post": "22",

"file": "ftp_test.txt"

},

"mappings": {

"email": "1",

"lastname": "2"

},

"listIds": [1],

"settings": {

"update_duplicates": "yes",

"delimiter": "comma"

}

}

');

6. Tell the API to output the Response

try {

$response = $request->send();

echo $response->getBody();

}

7. The final lines close the request

catch (HttpException $ex) {

echo $ex;

}

Translate »