Overview

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

The Method

TypeRequestMethod
RESTPOSThttps://[Your URL]/api/2.0/imports/sftp

Your method must be structured as follows:

Parameters

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

Property TypeDescriptionRequired
$credentialsstringThe credentials required to log into the SFTP 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
$listIds arrayAn 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
Property TypeDescriptionDefaultRequiredRead Only
HostnamestringThe SFTP hostname to connect to.emptyyesyes
UsernamestringThe username to use when connecting to the SFTP host. emptyyesyes
PasswordstringThe password to use when connecting to the SFTP. emptyyesyes
PortstringThe SFTP port21yesyes
FilestringThe location of the file on the SFTP serveremptyyesyes
$settings
Property TypeDescriptionDefaultRequired
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 file. emptyyes
DelimeterstringThe 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

Code Samples

<?php

$request = new HttpRequest();
$request->setUrl('<URL>/api/2.0/imports/sftp');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'content-type' => 'application/json',
  'authorization' => 'Basic YWRtaW5pc3RyYXRvcjpqSVYxT=='
));

$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"
    }
}
');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}