listBatchSubscribe()

Array of recipients’ emails with settings and merge fields are passed, but information (also array) about how many emails have been added to a specific list is returned.

listBatchSubscribe(string $id, array $batch, boolean $double_optin, boolean $update_existing) : struct

Input parameters
  • id - list ID
  • batch - array of emails. Each email is represented as an array where field names are taken from merge fields and their appropriate values are set.
  • double_optin - whether confirmation message will be sent (true, false) (optional). Default value is false.
    Value change of this parameter is deprecated. False value is used always.
  • update_existing - whether existing emails will be restored (true, false) (optional). Default value is false.

Information obtained


Array consisting of:

  • success_count - number of successfully added emails
  • error_count - number of unsuccessfully added emails
  • errors - array of error messages about each email. Each error message is represented as an array consisting of fields:
    • code - error code
    • message - error message
    • email - email address that raised error

Examples

mgapi_listBatchSubscribe.php
 $my_email, 'FNAME' => 'Joe');
$batch[] = array('EMAIL' => $boss_man_email, 'FNAME' => 'Boss');
$double_optin = true;
$update_existing = false;
 
$retval = $api->listBatchSubscribe($id, $batch, $double_optin, $update_existing);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to load listBatchSubscribe()!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "success:" . $retval['success_count'] . "\n";
    echo "errors:" . $retval['error_count'] . "\n";
    foreach ($retval['errors'] as $val) {
        echo "\t*" . $val['email'] . " failed\n";
        echo "\tcode:" . $val['code'] . "\n";
        echo "\tmsg :" . $val['message'] . "\n\n";
    }
}
xml-rpc_listBatchSubscribe.php
 new xmlrpcval($apikey),
                    'id' => new xmlrpcval($listId),
                    'batch' => php_xmlrpc_encode(
                            array(
                                array('EMAIL' => $my_email, 'FNAME' => 'Joe'),
                                array('EMAIL' => $boss_man_email, 'FNAME' => 'Boss')
                            )
                    ),
                    'double_optin' => new xmlrpcval(true),
                    'update_existing' => new xmlrpcval(false)
                ),
                'struct');
$f = new xmlrpcmsg('listBatchSubscribe', 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:" . $retval['success_count'] . "\n";
    echo "errors:" . $retval['error_count'] . "\n";
    foreach ($retval['errors'] as $val) {
        echo "\t*" . $val['email'] . " failed\n";
        echo "\tcode:" . $val['code'] . "\n";
        echo "\tmsg :" . $val['message'] . "\n\n";
    }
} else {
    echo "Unable to load listBatchSubscribe()!";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}
mgapi_listBatchSubscribe.py
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)
 
id = listId
batch = []
batch.append({'EMAIL': my_email, 'FNAME': 'Joe'})
batch.append({'EMAIL': boss_man_email, 'FNAME': 'Boss'})
double_optin = True
update_existing = False
 
retval = api.listBatchSubscribe(id, batch, double_optin, update_existing)
if api.errorCode:
    print "Unable to load listBatchSubscribe()!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "success:", retval['success_count']
    print "errors:", retval['error_count']
    for val in retval['errors']:
        print "\t*", val['email'], " failed"
        print "\tcode:", val['code']
        print "\tmsg :", val['message']

© 2010-2017 Mailigen. All rights reserved.