listMergeVars()

This function obtains merge fields (array) from database, as well as all the necessary parameters of these fields.

listMergeVars(string $id) : array
Input parametrs
  • id - list ID
Information obtained

Array of merge fields. Each merge field is represented as an array that includes:

  • name - name of merge field
  • req - whether this field is obligatory (true, false)
  • field_type - type of field (email, text, number, radio, grouping, dropdown, date, address, sms, website, image)
  • show - whether this field is shown in the list (true, false)
  • pubilc - whether this field is shown in the web signup forms (true, false)
  • order - serial number
  • default - default value
  • tag - merge field name that is used in forms and also in API functions such as listSubscribe and listUpdateMember
  • predefined_values - user predefined custom field values for radio, grouping and dropdown field types
    Important
    • Array of values and labels are returned.

Examples

mgapi_listMergeVars.php
listMergeVars($id);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to load listMergeVars()!";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Merge tags returned: " . sizeof($retval) . "\n";
    foreach ($retval as $i => $var) {
        echo "Var #$i:\n";
        echo "\tTag: " . $var['tag'] . "\n";
        echo "\tName: " . $var['name'] . "\n";
        echo "\tRequired: " . $var['req'] . "\n";
    }
}
xml-rpc_listMergeVars.php
 new xmlrpcval($apikey),
                    'id' => new xmlrpcval($listId)
                ),
                'struct');
$f = new xmlrpcmsg('listMergeVars', 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 "Merge tags returned: " . sizeof($retval) . "\n";
    foreach ($retval as $i => $var) {
        echo "Var #$i:\n";
        echo "\tTag: " . $var['tag'] . "\n";
        echo "\tName: " . $var['name'] . "\n";
        echo "\tRequired: " . $var['req'] . "\n";
    }
} else {
    echo "Unable to run listMergeVars()!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}
mgapi_listMergeVars.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
 
retval = api.listMergeVars(id)
if api.errorCode:
    print "Unable to load listMergeVars()!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Merge tags returned: ", len(retval)
    if isinstance(retval, dict):
        for i,var in retval.items():
            print "Var #%d:" % (i)
            print "\tTag: ", var['tag']
            print "\tName: ", var['name']
            print "\tRequired: ", var['req']
    elif isinstance(retval, list):
        for i,var in enumerate(retval):
            print "Var #%d:" % (i)
            print "\tTag: ", var['tag']
            print "\tName: ", var['name']
            print "\tRequired: ", var['req']

© 2010-2017 Mailigen. All rights reserved.