iContact api integration using php
These days playing with icontact email marketing system with php api really kills my time for some operations. iContact api integration using php here i just explain what we can do with icontact api 2.2 and what we can’t achieve. First of all the icontact api is most similar to mailchimp . lot of options for managing subscribers and predefined email templates also you can create custom email templates your own.
These days the email marketing is an unavoidable procedure for growing business in many cases. So just start with iContact api integration using php first you have to sign up with icontact for getting your Account Id and Client Id here.
Then you can download the iContact api integration using php from here. or customized api for icontact from here. Then what you can do with iconact api 2.2 in php.
First you have to create a user interface file here i just create index.php and first section should be include the icontact library file and make a connection with icontact server by setting your credential as follows.
require_once('iContactApi.php');
// Store the singleton
$oiContact = iContactApi::getInstance();
$oiContact->setAccountId(ACC_ID);/// Account Id
$oiContact->setClientFolderId(CLIENT_FD_ID);/// Client folder Id
.
Then if you download the library from icontact you will get an example file that mention lot of example for adding removing and fetching data from icontact account using php api. some are here.
// Try to make the call(s)
try {
// are examples on how to call the iContact PHP API class
// Grab all contacts
var_dump($oiContact->getContacts());
// Grab a contact
var_dump($oiContact->getContact(42094396));// get an existing contact with ist id
// Create a contact
var_dump($oiContact->addContact('joe@shmoe.com', null, null, 'Joe', 'Shmoe', null, '123 Somewhere Ln', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', null));
// Get messages
var_dump($oiContact->getMessages());
// Create a list
var_dump($oiContact->addList('somelist', 1698, true, false, false, 'Just an example list', 'Some List'));// sec arg is welcome message number
// Subscribe contact to list
var_dump($oiContact->subscribeContactToList(42094396, 179962, 'normal'));//arg contactid,list id , status
// Grab all campaigns
var_dump($oiContact->getCampaigns());
// Create message
var_dump($oiContact->addMessage('An Example Message', 585, '<h1>An Example Message</h1>', 'An Example Message', 'ExampleMessage', 33765, 'normal'));//sec arg is campain id and sec last arg is list id
// Schedule send
var_dump($oiContact->sendMessage(array(33765), 179962, null, null, null, mktime(0, 0, 0, 10, 03, 2012)));
// Upload data by sending a filename (execute a PUT based on file contents)
var_dump($oiContact->uploadData('/path/to/file.csv', 179962));
// Upload data by sending a string of file contents
$sFileData = file_get_contents('/path/to/file.csv'); // Read the file
var_dump($oiContact->uploadData($sFileData, 179962)); // Send the data to the API
} catch (Exception $oException) { // Catch any exceptions
// Dump errors
var_dump($oiContact->getErrors());
// Grab the last raw request data
var_dump($oiContact->getLastRequest());
// Grab the last raw response data
var_dump($oiContact->getLastResponse());
}
In additional with above methods you can define your own methods by using little study about this . Here i just explain how we can move a contact from one list to another this will support only with icontact api 2.2 or more.
$res = $oiContact->moveSubscriptionToList('48440_33785065', 48439, 'normal');
//arguments are subscription Id,new list id, Status (Subscription id is listid_contactId)
In the library file should have following code.
public function moveSubscriptionToList($sSubscriptionId, $iListId, $sStatus = 'normal') {
// Valid statuses
$aValidStatuses = array('normal', 'pending', 'unsubscribed');
// Check for a valid status
if (!empty($sStatus) && !in_array($sStatus, $aValidStatuses)) {
$sStatus = 'normal';
}
// Setup the subscription and make the call
$aSubscription = $this->makeCall("/a/{$this->setAccountId()}/c/{$this->setClientFolderId()}/subscriptions/{$sSubscriptionId}", 'PUT', array(
'listId' => $iListId,
'status' => $sStatus
), 'subscription');
// Return the subscription
return $aSubscription;
}
Ok now you will get some idea about how to manage contact inside list right ? Also lot of other custom methods you can add in the library for your requirement.
$res = $oiContact->getContactsWithListId(48439);//needs to get all the contact from a list
The iContact api integration using php not supporting the unsubscribe option of contacts they do not provide this option with api. But with the move to another list feature you can achieve this create one extra list called Unsubscribed and move all unsubscribed users to this list.
Also the search option with email is not working with php api Iam trying on that if that get available post soon.
Enjoy iconact integration using php api Download library file ? 🙂 🙂 🙂
4 thoughts on “iContact api integration using php”
Hi, nice tutorial and api, but you have problem in code (if its yours). You have throw error in makeCall but this method is call by other method in api and on one of this method can catch this throws (miss try block)
Thanks for the head up!
Thanks for this information. It is very helpful. Do you have an example of how I would take information from unbounce and import it into icontact?
You cannot do any operations with bounced and unsubscribed status contacts. API will not allow subscribe back or move to other list for these type of contacts.
You can use basic contacts search with different status like
icp/a//c//contacts?status=unlisted.
Detailed documentation can be found here http://www.icontact.com/developerportal/documentation/contacts/.
Also check my related post with iContact API it has several additional methods that may help you..