campaignCreate()

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
Input parameters
  • type - type of campaign (HTML, plain, auto)
  • options - campaign settings. Array consisting of: 
    • list_id - list ID or array of multiple lists IDs
    • segment_id - segment ID or array of multiple segment IDs (optional). User created segment based only on given list ID.
      id parameter value must be used here. See All segments for retrieving segment ID value.
    • subject - subject line
    • from_email - reply To email address. Recipient replies will go to this email address.
    • from_name - sender's name, from who the campaign will be received.
    • sender - sender email (optional). Specify an e-mail address from which the campaign will be received. Only available for PRO Users. Your main e-mail address is used by default.
    • personalize_to_field - personalize the email's To: field information with the recipients First Name if it is stored in your subscriber list information (true, false) (optional). Default value is true.
    • tracking - campaign tracking (optional). Array of boolean values for following options:
      • opens - (true, false). Default value is true.
      • html_clicks - (true, false). Default value is true.
      • text_clicks - (true, false). Default value is false.
    • title - name of campaign (optional). By default subject line is used as a name of campaign
    • analytics - web analytics integration option (optional). Array of options for Google analytics tool:
      • google - your Google campaign title. By using this option, you will be able to track traffic from emails under Acquisition > All Traffic > Channels in your Google Analytics account.
    • generate_text - plain text generation (true, false) (optional). If set to true, text from HTML will be generated. Default value is false.
    • auto_footer - whether to send out the campaign with a standard signature (true, false) (optional). Default value is false.
    • authenticate - authenticate the campaign (true, false) (optional). Will work if authenticated and activated domains are added to system. Default value is false.
    • inline_img - send images as attachment - inline images (true, false) (optional). Default value is false. Only available for users with Inline image add-on.
    • time_match - use time match to deliver scheduled campaigns based on recipient's time zone (true, false). Default value is false.
    • ln - text language (cn, dk, en, ee, fi, fr, de, it, jp, lv, lt, no, pl, pt, ru, es, se) (optional). Specify language for texts by including header and footer.
  • content - campaign email content. Array consisting of:
    • html - HTML content.
    • plain - plain text content. If this value is omitted, then plain text generation option should be switched on (set to true), to ensure there is a plain text content.OR
    • url - URL from which import HTML. If parameter plain is omitted, then generate_text option should be switched on (set to true), to ensure there is a plain text content.
    • plain - plain text content. If this value is omitted, then generate_text option should be switched on (set to true), to ensure there is a plain text content.OR
    • archive - archive file encoded with with Base64. If this value is set, above values will be overwritten.
    • archive_type - archive type (optional). Following archive formats are supported: zip, tar.gz, tar.bz2, tar, tgz, tbz. By default zip format is used, if no value is set.OR
    • template_id - user defined template ID to be used for generating HTML content of the email
  • type_opts - autoresponder campaign settings (optional). Array consisting of:
    • offset-units - time unit of autoresponder (day, week, month, year). One of the given values must be specified.
    • offset-time - time of autoresponder. Value greather than 0 (zero) must be specified.
    • offset-dir - moment of sending (before, after). Default value is after.
    • event - event (signup, date, annual) after which autoresponder campaign is sent (optional). Default value is signup.
    • event-datemerge - merge tag that is taken into account when sending campaign (optional). This option has to be set when chosen event option is "date" or "annual".

Information obtained
  • ID of the new campaign

Examples

mgapi_campaignCreate.php
<?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 = 'html';
$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'
);
 
 
 
 
$retval = $api->campaignCreate($type, $options, $content);
 
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";
}
xml-rpc_campaignCreate.php
 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";
}

mgapi_campaignCreate.py
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

© 2010-2017 Mailigen. All rights reserved.