Campaign list is returned by request. When sending a request, it is possible to perform data selection due to which campaigns will be returned from the database. Selection parameters are transferred, while campaign list (array) is returned. If selection parameters are not transferred, information about all campaigns is returned.
campaigns(array $filters, integer $start, integer $limit) : array
Array of campaigns. Each campaign is represented as an array that includes:
campaigns(); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaigns()!"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo sizeof($retval) . " Campaigns Returned:\n"; foreach ($retval as $c) { echo "Campaign Id: " . $c['id'] . " - " . $c['title'] . "\n"; echo "\tStatus: " . $c['status'] . " - type = " . $c['type'] . "\n"; echo "\tsent: " . $c['send_time'] . " to " . $c['emails_sent'] . " members\n"; } }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) retval = api.campaigns() if api.errorCode: print "Unable to load campaigns()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "%d Campaigns Returned:" % (len(retval)) for c in retval: print "Campaign Id: %s - %s" % (c['id'], c['title']) print "\tStatus: %s - type = %s" % (c['status'], c['type']) print "\tsent: %s to %s members" % (c['send_time'], c['emails_sent'])
New campaign is created and array of parameters is passed including information about type of campaign, campaign settings, email content and autoresponder campaign if such is created.
campaignCreate(string $type, array $options, array $content, array $type_opts) : string
<?php /** * This Example shows how to campaignCreate using the MGAPI.php class and do some basic error checking. */ require_once 'inc/MGAPI.class.php'; require_once 'inc/config.inc.php'; //contains apikey $api = new MGAPI($apikey); $type = 'absplit'; $options = array( 'list_id' => $listId, //'segment_id' => 'YOUR_SEGMENT_ID', 'subject' => 'Test Newsletter Subject', 'from_email' => 'example@example.org', 'from_name' => 'DEMO, Inc.', //'sender' => 'example@example.org', // This Email Sender Information will be used (Only available for PRO Users) 'tracking' => array( 'opens' => true, 'html_clicks' => true, 'text_clicks' => false ), 'analytics' => array( 'google' => 'My Google Analytics Campaign Title' ), 'generate_text' => true, 'title' => 'Test Newsletter Title' ); /* $content = array( 'template_id' => 'template_id', ); */ /* $content = array( 'html' => 'some pretty html content *[UNSUB]* message', 'plain' => 'some pretty plain content *[UNSUB]* message', ); */ /* $content = array( 'url' => 'http://www.google.com', 'plain' => 'some pretty plain content *[UNSUB]* message', ); */ $content = array( 'archive' => base64_encode(file_get_contents('archive.tar')), 'archive_type' => 'tar' ); $testType = 'time'; $options['title'] = "{$options['title']} (test type: {$testType})"; $type_opts = [ 'test_type' => $testType, 'test_size' => 40, 'winner_by' => 'click', 'winner_after' => 12, // hours 'send_manual' => false, 'winner_inconclusive' => 'B', ]; switch ($testType) { case 'content': $content = [ 'html_A' => 'Content A, some pretty html content #[UNSUB]# message', 'html_B' => 'Content B, some pretty html content #[UNSUB]# message', ]; unset($content['html']); break; case 'subject': $options += [ 'subject_A' => 'Test Newsletter Subject A', 'subject_B' => 'Test Newsletter Subject B', ]; unset($options['subject']); break; case 'from': $options += [ 'from_name_A' => 'DEMO A, Inc.', 'from_name_B' => 'DEMO B, Inc.', ]; unset($options['from_name']); break; case 'time': $options += [ 'schedule_time_A' => date('Y-m-d H:00:00', strtotime('+2 days')), 'schedule_time_B' => date('Y-m-d H:00:00', strtotime('+2 days +2 hours')), ]; break; } $retval = $api->campaignCreate($type, $options, $content, $type_opts); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignCreate()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "New Campaign ID:" . $retval . "\n"; }
<?php /** * This Example shows how execute a campaignCreate and check the result using XML-RPC. * Note that we are using the PEAR XML-RPC client and recommend others do as well. */ require_once 'xmlrpc-3.0.0.beta/xmlrpc.inc'; require_once 'inc/config.inc.php'; $apiUrl = parse_url($apiUrl); $v = new xmlrpcval(array( 'apikey' => new xmlrpcval($apikey), 'type' => new xmlrpcval('html'), 'options' => php_xmlrpc_encode( array( 'list_id' => $listId, 'subject' => 'Test Newsletter Subject', 'from_email' => 'example@example.org', 'from_name' => 'DEMO, Inc.', 'tracking' => array( 'opens' => true, 'html_clicks' => true, 'text_clicks' => false ), 'analytics' => array( 'google' => 'my_google_analytics_key' ), 'title' => 'Test Newsletter Title' ) ), 'content' => php_xmlrpc_encode( array( //'template_id' => 'template_id', //'html' => 'some pretty html content *[UNSUB]* message', //'plain' => 'some pretty plain content *[UNSUB]* message', //'url' => 'http://www.google.com', 'archive' => base64_encode(file_get_contents('archive.tar')), 'archive_type' => 'tar' ) ) ), 'struct'); $f = new xmlrpcmsg('campaignCreate', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "New Campaign ID:" . $retval . "\n"; } else { echo "Unable to run campaignCreate()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI import base64 # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) type = 'html' options = { 'list_id': listId, 'subject': 'Test Newsletter Subject', 'from_email': 'example@example.org', 'from_name': 'DEMO, Inc.', 'tracking': { 'opens': True, 'html_clicks': True, 'text_clicks': False }, 'analytics': { 'google': 'my_google_analytics_key' }, 'title': 'Test Newsletter Title' } content = { #'template_id': 'template_id', #'html': 'some pretty html content *[UNSUB]* message', #'plain': 'some pretty plain content *[UNSUB]* message', #'url': 'http://www.google.com', 'archive': base64.encodestring(open('archive.zip').read()), 'archive_type': 'zip' } retval = api.campaignCreate(type, options, content) if api.errorCode: print "Unable to load campaignCreate()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "New Campaign ID:", retval
Update of one of the previously created values of campaign parameters.
campaignUpdate(string $cid, string $name, mixed $value) : boolean
campaignUpdate($cid, $name, $value); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignUpdate()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "SUCCESS! \n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId), 'name' => new xmlrpcval('title'), 'value' => new xmlrpcval('New Title') ), 'struct'); $f = new xmlrpcmsg('campaignUpdate', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "SUCCESS! \n"; } else { echo "Unable to run campaignUpdate()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId name = 'title' value = 'New Title' retval = api.campaignUpdate(cid, name, value) if api.errorCode: print "Unable to load campaignUpdate()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "SUCCESS!"
Submit request of delivering campaign that previously was saved as a draft. Campaign is sent immediately. Campaign ID number is passed as a parameter.
campaignSendNow(string $cid) : boolean
campaignSendNow($cid); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignSendNow()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Campaign Sent!\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId) ), 'struct'); $f = new xmlrpcmsg('campaignSendNow', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Campaign Sent!\n"; } else { echo "Unable to run campaignSendNow()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId retval = api.campaignSendNow(cid) if api.errorCode: print "Unable to load campaignSendNow()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Campaign Sent!"
Campaign delivery is scheduled. Time is set according GMT, but if a specific time zone needs to be set up, required number of hours have to be added or subtracted. Time is written in YYYY-MM-DD HH:II:SS +GMT format. Example of time format: ‘2020-05-18 11:59:21 +0100’, where ‘+0100’ is an added hour to the standard time.
campaignSchedule(string $cid, string $schedule_time) : boolean
campaignSchedule($cid, $schedule_time); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignSchedule()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Campaign Scheduled to be delivered $schedule_time!\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId), 'schedule_time' => new xmlrpcval($schedule_time) ), 'struct'); $f = new xmlrpcmsg('campaignSchedule', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Campaign Scheduled to be delivered $schedule_time!\n"; } else { echo "Unable to run campaignSchedule()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId schedule_time = '2020-05-18 11:59:21' retval = api.campaignSchedule(cid, schedule_time) if api.errorCode: print "Unable to load campaignSchedule()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Campaign Scheduled to be delivered %s!" % (schedule_time)
Campaign delivery time is unscheduled. Campaign is saved as a draft and is not delivered.
campaignUnschedule(string $cid) : boolean
campaignUnschedule($cid); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignUnschedule()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Campaign Unscheduled!\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId) ), 'struct'); $f = new xmlrpcmsg('campaignUnschedule', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Campaign Unscheduled!\n"; } else { echo "Unable to run campaignUnschedule()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId retval = api.campaignUnschedule(cid) if api.errorCode: print "Unable to load campaignUnschedule()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Campaign Unscheduled!"
Submit request of delivering test mails of campaign which previously was saved as a draft.
campaignSendTest(string $cid, array $test_emails, string $send_type) : boolean
campaignSendTest($cid, $test_emails); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignSendTest()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Campaign Tests Sent!\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId), 'test_emails' => php_xmlrpc_encode( array($my_email, $boss_man_email) ) ), 'struct'); $f = new xmlrpcmsg('campaignSendTest', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Campaign Tests Sent!\n"; } else { echo "Unable to run campaignSendTest()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId test_emails = [my_email, boss_man_email] retval = api.campaignSendTest(cid, test_emails) if api.errorCode: print "Unable to load campaignSendTest()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Campaign Tests Sent!"
Submit request and as a result obtain a list (array) with saved templates in user’s account.
campaignTemplates(integer $start, integer $limit) : array
Array of Templates. Each template is represented as an array that includes:
campaignTemplates(); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignTemplates()!"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Your templates:\n"; foreach ($retval as $tmpl) { echo "\t" . $tmpl['id'] . " - " . $tmpl['name'] . " - " . $tmpl['layout'] . "\n"; } }
new xmlrpcval($apikey) ), 'struct'); $f = new xmlrpcmsg('campaignTemplates', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Your templates:\n"; foreach ($retval as $tmpl) { echo "\t" . $tmpl['id'] . " - " . $tmpl['name'] . " - " . $tmpl['layout'] . "\n"; } } else { echo "Unable to run campaignTemplates()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) retval = api.campaignTemplates() if api.errorCode: print "Unable to load campaignTemplates()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Your templates:" for tmpl in retval: print "\t", tmpl['id'], " - ", tmpl['name'], " - ", tmpl['layout']
Existing campaign is replicated and the ID of the new campaign is returned.
campaignReplicate(string $cid) : string
campaignReplicate($cid); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignReplicate()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "New Campaign Id = " . $retval . "\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId) ), 'struct'); $f = new xmlrpcmsg('campaignReplicate', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "New Campaign Id = " . $retval . "\n"; } else { echo "Unable to run campaignReplicate()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId retval = api.campaignReplicate(cid) if api.errorCode: print "Unable to load campaignReplicate()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "New Campaign Id = ", retval
Delete campaign from the account of a specific user.
campaignDelete(string $cid) : boolean
campaignDelete($cid); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load campaignDelete()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Campaign Deleted!\n"; }
new xmlrpcval($apikey), 'cid' => new xmlrpcval($campaignId) ), 'struct'); $f = new xmlrpcmsg('campaignDelete', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Campaign Deleted!\n"; } else { echo "Unable to run campaignDelete()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) cid = campaignId retval = api.campaignDelete(cid) if api.errorCode: print "Unable to load campaignDelete()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Campaign Deleted!"