-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples folder from original source archive
- Loading branch information
Showing
36 changed files
with
3,843 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
//API Key - see http://admin.mailchimp.com/account/api | ||
$apikey = 'YOUR MAILCHIMP APIKEY'; | ||
|
||
// A List Id to run examples against. use lists() to view all | ||
// Also, login to MC account, go to List, then List Tools, and look for the List ID entry | ||
$listId = 'YOUR MAILCHIMP LIST ID - see lists() method'; | ||
|
||
// A Campaign Id to run examples against. use campaigns() to view all | ||
$campaignId = 'YOUR MAILCHIMP CAMPAIGN ID - see campaigns() method'; | ||
|
||
//some email addresses used in the examples: | ||
$my_email = '[email protected]'; | ||
$boss_man_email = '[email protected]'; | ||
|
||
//just used in xml-rpc examples | ||
$apiUrl = 'http://api.mailchimp.com/1.3/'; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
This Example shows how to add a new API key using the MCAPI.php class and do | ||
some basic error checking. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$retval = $api->apiKeyAdd($username, $password); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to load Add a New API Key()!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "New API Key:".$retval."\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
This Example shows how to expire an API key using the MCAPI.php class and do | ||
some basic error checking. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$retval = $api->apikeyExpire($username, $password); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to Expire API Key()!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "API Key Expired:".$api->api_key."\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
This Example shows how to add grab a full set of Campaign Abuse Reports wtih | ||
some basic error checking. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
// Connect to the MailChimp api with an API Key | ||
$api = new MCAPI($apikey); | ||
|
||
$reports = $api->campaignAbuseReports($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to run campaignAbuseReports()!\n"; | ||
echo "\tCode=".$api->errorCode."\n"; | ||
echo "\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "Total reports:".$reports['total']."\n"; | ||
echo "Reports returned:".sizeof($reports['data'])."\n"; | ||
foreach ($reports['data'] as $rpt){ | ||
echo $rpt['date']." - ".$rpt['email']." - ".$rpt['type']."\n"; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
This Example shows how to retrieve campaign Advice messages from the API with | ||
some basic error checking. | ||
**/ | ||
|
||
// Include the MailChimp API code. Do Not Edit This! | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
// Connect to the MailChimp server with the user's credentials. | ||
$api = new MCAPI($apikey); | ||
|
||
$advice = $api->campaignAdvice($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to run campaignAdvice()!\n"; | ||
echo "\tCode=".$api->errorCode."\n"; | ||
echo "\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
if (sizeof($advice)>0){ | ||
foreach($advice as $adv){ | ||
echo "Type: ".$adv['type']."\n"; | ||
echo "Message: ".$adv['msg']."\n"; | ||
} | ||
} else { | ||
echo "Sorry, no advice for this campaign!\n"; | ||
} | ||
} | ||
|
||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
This Example shows how to retrieve Analytics data collected for a campaign with | ||
some basic error checking. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$stats = $api->campaignAnalytics($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to run campaignAnalytics()!\n"; | ||
echo "\tCode=".$api->errorCode."\n"; | ||
echo "\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "Visits: ".$stat['visits']."\n"; | ||
echo "Pages: ".$rpt['pages']."\n"; | ||
echo "Goals ".$rpt['type']."\n"; | ||
if ($stat['goals']){ | ||
foreach($stat['goals'] as $goal){ | ||
echo "\t".$goal['name']." => ".$goal['conversions']."\n"; | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
This Example shows how to retrieve full Bounce Message data associated with a | ||
campaign and do some basic error checking. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$msgs = $api->campaignBounceMessages($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to run campaignBounceMessages()!\n"; | ||
echo "\tCode=".$api->errorCode."\n"; | ||
echo "\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "Total bounces:".$msgs['total']."\n"; | ||
echo "Bounces returned:".sizeof($msgs['data'])."\n"; | ||
foreach ($msgs['data'] as $msg){ | ||
echo $msg['date']." - ".$msg['email']."\n"; | ||
echo substr($msg['message'],0,150)."\n\n"; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
This Example shows how to pull and iterate through a campaignClickStats call via | ||
using the MCAPI wrapper class. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$stats = $api->campaignClickStats($campaignId); | ||
if ($api->errorCode){ | ||
echo "Unable to load campaignClickStats()!\n\t"; | ||
echo "Code=".$api->errorCode."\n\t"; | ||
echo "Msg=".$api->errorMessage."\n"; | ||
} else { | ||
if (sizeof($stats)==0){ | ||
echo "No stats for this campaign yet!\n"; | ||
} else { | ||
foreach($stats as $url=>$detail){ | ||
echo "URL: ".$url."\n"; | ||
echo "\tClicks = ".$detail['clicks']."\n"; | ||
echo "\tUnique Clicks = ".$detail['unique']."\n"; | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
This Example shows how to create a basic campaign via the MCAPI class. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$type = 'regular'; | ||
|
||
$opts['list_id'] = 'f9ee6d8616'; | ||
$opts['subject'] = 'Test Newsletter Subject'; | ||
$opts['from_email'] = '[email protected]'; | ||
$opts['from_name'] = 'ACME, Inc.'; | ||
|
||
$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false); | ||
|
||
$opts['authenticate'] = true; | ||
$opts['analytics'] = array('google'=>'my_google_analytics_key'); | ||
$opts['title'] = 'Test Newsletter Title'; | ||
|
||
$content = array('html'=>'some pretty html content *|UNSUB|* message', | ||
'text' => 'text text text *|UNSUB|*' | ||
); | ||
/** OR we could use this: | ||
$content = array('html_main'=>'some pretty html content', | ||
'html_sidecolumn' => 'this goes in a side column', | ||
'html_header' => 'this gets placed in the header', | ||
'html_footer' => 'the footer with an *|UNSUB|* message', | ||
'text' => 'text content text content *|UNSUB|*' | ||
); | ||
$opts['template_id'] = "1"; | ||
**/ | ||
|
||
$retval = $api->campaignCreate($type, $opts, $content); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to Create New Campaign!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "New Campaign ID:".$retval."\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
This Example shows how to send Delete Campaigns via the MCAPI class. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$retval = $api->campaignDelete($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to Delete Campaign!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "Campaign Deleted!\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
This Example shows how to retrieve email domain performance for a campaign via | ||
the API and do some basic error checking. | ||
**/ | ||
// Include the MailChimp API code. Do Not Edit This! | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$domains = $api->campaignEmailDomainPerformance($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to run campaignEmailDomainPerformance()!\n"; | ||
echo "\tCode=".$api->errorCode."\n"; | ||
echo "\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
if (sizeof($domains)==0){ | ||
echo "No Email Domain stats yet!\n"; | ||
} else { | ||
foreach($domains as $domain){ | ||
echo $domain['domain']."\n"; | ||
echo "\tEmails: ".$domain['emails']."\n"; | ||
echo "\tOpens: ".$domain['opens']."\n"; | ||
echo "\tClicks: ".$domain['clicks']."\n"; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
This Example shows how to iterate through the AIM stats for every email address | ||
associated with a campaign and do some basic error checking. | ||
**/ | ||
|
||
// Include the MailChimp API code. Do Not Edit This! | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$limit = 5; | ||
for($i=0;$i<5;$i++){ | ||
echo "====== Page $i : START ======\n"; | ||
$allstats = $api->campaignEmailStatsAIMAll($campaignId, $i*$limit, $limit); | ||
if ($api->errorCode){ | ||
echo "Unable to run campaignEmailStatsAIMAll()"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
exit; | ||
} | ||
if ($allstats['total']==0){ | ||
echo "No more stats available!\n"; | ||
exit; | ||
} | ||
foreach($allstats['data'] as $email=>$stats){ | ||
echo "[".$email."]\n"; | ||
foreach($stats as $stat){ | ||
echo "\t".$stat['action']." @ ".$stat['timestamp']; | ||
if ($stat['action']=='click'){ | ||
echo "\n\tURL = ".$stat['url']."\n"; | ||
} else { | ||
echo "\n"; | ||
} | ||
} | ||
} | ||
echo "====== Page $i : END ======\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
This Example shows how to send Replicate Campaigns via the MCAPI class. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$retval = $api->campaignReplicate($campaignId); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to Replicate Campaign!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "New Campaign Id = $retval\n"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
This Example shows how to schedule a campaign for future delivery | ||
via the MCAPI class. | ||
**/ | ||
require_once 'inc/MCAPI.class.php'; | ||
require_once 'inc/config.inc.php'; //contains apikey | ||
|
||
$api = new MCAPI($apikey); | ||
|
||
$schedule_for = '2018-04-01 09:05:21'; | ||
$retval = $api->campaignSchedule($campaignId, $schedule_for); | ||
|
||
if ($api->errorCode){ | ||
echo "Unable to Schedule Campaign!"; | ||
echo "\n\tCode=".$api->errorCode; | ||
echo "\n\tMsg=".$api->errorMessage."\n"; | ||
} else { | ||
echo "Campaign Scheduled to be delivered $schedule_for!\n"; | ||
} | ||
|
||
?> |
Oops, something went wrong.