PHP code example of 2ur1st / emarsys

1. Go to this page and download the library: Download 2ur1st/emarsys library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

2ur1st / emarsys example snippets




define('EMARSYS_API_USERNAME', 'your_username');
define('EMARSYS_API_SECRET', 'your_secret');

$httpClient = new CurlClient();
$client = new Client($httpClient, EMARSYS_API_USERNAME, EMARSYS_API_SECRET);

// Retrieve a contact from his email address
$response = $client->getContact(array(3 => '[email protected]'));

// Create a contact with just his email information
$response = $client->createContact(array(3 => '[email protected]'));

// Create a more complex contact
$response = $client->createContact(array(
    'email' => '[email protected]',
    'gender' => $client->getChoiceId('gender', 'male'),
    'salutation' => $client->getChoiceId('salutation', 'mr'),
    'firstName' => 'John',
    'lastName' => 'Doe',
    'birthDate' => '2014-03-27',
    'address' => 'Forgotten street 85B',
    'zip' => '1000',
    'city' => 'Brussels',
    'country' => 17,
    'language' => 3,
));

$client->addFieldsMapping(array('petName' => 7849, 'twitter' => 7850));`

$response = $client->createContact(array(1 => 'John', 2 => 'Doe', 3 => '[email protected]'));
$response = $client->createContact(array('firstName' => 'John', 'lastName' => 'Doe', 'email' => '[email protected]'));

$fieldId = $client->getFieldId('firstName');
// will return 1;
$fieldName= $client->getFieldName(1);
// will return 'firstName';

$client = new Client(EMARSYS_API_USERNAME, EMARSYS_API_SECRET, array('firstName' => 1, 'lastName' => 2));

$client->addChoicesMapping(array('gender' => array('male' => 1, 'female' => 2)));

$response = $client->getFieldChoices(5);
$response = $client->getFieldChoices('gender');

$choiceId = $client->getChoiceId('gender', 'male');
// will return 1;
$choiceName= $client->getChoiceName('gender', 1);
// will return 'male';

$client = new Client(EMARSYS_API_USERNAME, EMARSYS_API_SECRET, array(), array('gender' => array('male' => 1, 'female' => 2)));
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Emarsys as a dependency
php composer.phar