tags:

views:

273

answers:

2

Hi,

I have somewhat of a knowledge of the PHP coding language and I would like to connect the Campaign Monitor API(Link) with my website, so that when the user enters something into the form on my site it will add it to the database on the Campaign Monitor servers. I found the PHP code example zip file, but it contains like 30 files, and I have no idea where to begin.

Does anyone know of a tutorial anywhere that explains how to connect to the API in a step-by-step manner? The code files by themselves include to much code that I may not need for simply connecting to the database and adding and deleting users, since I only want to give the user the power to add and delete users from the Mailing List.

+1  A: 

This actually looks pretty straightforward. In order to use the API, you simply need to include() the CMBase.php file that is in that zip file.

Once you've included that file, you can create a CampaignMonitor object, and use it to access the API functions. I took this example out of one of the code files in there:

require_once('CMBase.php');

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_id = null;
$campaign_id = null;
$list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id );

//This is the actual call to the method, passing email address, name.
$result = $cm->subscriberAdd('[email protected]', 'Joe Smith');

You can check the result of the call like this (again taken from their code examples):

if($result['Result']['Code'] == 0)
 echo 'Success';
else
 echo 'Error : ' . $result['Result']['Message'];

Since you're only interested in adding a deleting users from a mailing list, I think the only two API calls you need to worry about are subscriberAdd() and subscriberUnsubscribe():

$result = $cm->subscriberAdd('[email protected]', 'Joe Smith');
$result = $cm->subscriberUnsubscribe('[email protected]');

Hope that helps. The example files that are included in that download are all singular examples of an individual API method call, and the files are named in a decent manner, so you should be able to look at any file for an example of the corresponding API method.

zombat
Thank you SO very much! I wish I could give you more than one point for this answer. this is exactly what I need! You rock!
zeckdude
No problem, happy to help. :)
zombat
How would I grab the information from a form instead of the generic [email protected] example? I want to make it dynamic.
zeckdude
A: 

Same question as Chris!

Si