Listrak is a full service email firm founded in 1999 that provides solutions and services that increases the value of your customer’s email. They developed strategies and marketing solutions that help the company to drive their ROI (Return of Investment) to its full potential.
Like most email service company, Listrak build their own API in order to manipulate web services. Listrak used SOAP (Simple Object Access Protocol) and WSDL (Web Service Definition Language). They also recommend SoapUI, a tool that provides the ability to invoke, inspect and stimulate web services.
Requirements
In order to integrate Listrak API on PHP you need the following requirements:
a.
Listrak Account (Username and Password).
b.
PHP Soap library
PHP Integration Sample Code
<?php
/**
* LISTRAK INTEGRATION
* @Requirements
* 1. Listrak Account, Username and Password
*/
$sh_param = array(
'UserName' => "GTan",
'Password' => "Admin12345"
);
$authvalues = new SoapVar($sh_param, SOAP_ENC_OBJECT);
$headers[] = new SoapHeader("http://webservices.listrak.com/v31/", 'WSUser', $sh_param );
$soapClient = new SoapClient("https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL", array('trace'=> 1, 'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2));
$soapClient->__setSoapHeaders($headers);
$params = array(
'WSContact' => array(
'EmailAddress' => 'test@test.com',
'ListID' => 259048,
'ContactProfileAttribute' => array(
array('AttributeID' => 1480218 , 'Value' => 'duanereade')
)
),
'ProfileUpdateType' => 'Overwrite',
'ExternalEventIDs' => "",
'OverrideUnsubscribe' => TRUE
);
try {
$rest = $soapClient->SetContact($params);
// echo $rest->SetContactResult;
} catch (SoapFault $e) {
echo '<pre>';
print($e->getMessage());
echo '</pre>';
}
?>
Code Breakdown
Note: If you don't have any idea on how to use SOAP it is better to read
PHP SOAP Manual first.
Here is the detailed explanation of the code:
First off is supply the correct listrak credential.
$sh_param = array(
'UserName' => "YourListrakUsername",
'Password' => "YourListrakPassword"
);
The second thing is to prepare the
SoapVar and
SoapHeader. Listrak use "http://webservices.listrak.com/v31/" for the namespace of the header element and "WSUser" for the name of the SoapHeader Object.
$authvalues = new SoapVar($sh_param, SOAP_ENC_OBJECT);
$headers[] = new SoapHeader("http://webservices.listrak.com/v31/", 'WSUser', $sh_param );
Connect to Listrak
SoapClient using the defined headers and Listrak credentials.
$soapClient = new SoapClient("https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL", array('trace'=> 1, 'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2));
There are two parameters that you need to pass when calling SoapClient. The first is the
WSDL URL, Listrak WSDL is https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL. The second parameter are array option of the SoapClient. In this parameter you can set up several options such as soap version, exceptions etc. Please refer PHP
SoapClient for more info.
Next, you need to set the Soap Header using the following
setSoapHeader Object.
$soapClient->__setSoapHeaders($headers);
In order to subscribe or set contact info on Listrak, you need to used their defined web methods. View
complete list.
In this particular code, I used setContact method. This method will attempts to subscribe or update a contact to a specified list of with profile data and external events.
$params = array(
'WSContact' => array(
'EmailAddress' => 'test@test.com',
'ListID' => 259048,
'ContactProfileAttribute' => array(
array('AttributeID' => 1480218 , 'Value' => 'duanereade')
)
),
'ProfileUpdateType' => 'Overwrite',
'ExternalEventIDs' => "",
'OverrideUnsubscribe' => TRUE
);
You can view the complete information about setContact method
here.
Now, the last part is to pass the parameter to setContact method.
try {
$rest = $soapClient->SetContact($params);
echo $rest->SetContactResult;
} catch (SoapFault $e) {
echo '<pre>';
print($e->getMessage());
echo '</pre>';
}