Account settings

MGAPI()

Function is used to connect Mailigen API. It is necessary to use API key as an additional parameter.

MGAPI(string $apikey, boolean $secure)

Input parameters

  • apikey - Mailigen user API key
  • secure - whether to use secure SSL connection (true, false) (optional). Default value is false.

Examples

PHP

require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
 
$api = new MGAPI($apikey);

Python

from lib.config import * #contains apikey
from lib.MGAPI import MGAPI
 
api = MGAPI(apikey)

apikeys()

Request is sent by using login data, and as a result, API keys of a specific user account are returned.

apikeys(string $username, string $password, boolean $expired) : array

Input parameters

  • username - Mailigen username
  • password - Mailigen password
  • expired - expired API keys (optional):
    • true - to return all API keys
    • false (default value) - to return only active API keys

Information obtained

Array of API keys. Each key is represented as an array that includes:

  • apikey - API key
  • created_at - date of key creation
  • expired_at - date of key deactivation

Examples

mgapi_apikeys.php

apikeys($username, $password, $expired);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to get API keys!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "All API Keys for your account:\n";
    foreach ($retval as $key) {
        echo "key = " . $key['apikey'] . "\n";
        echo "\tcreated: = " . $key['created_at'] . "\n";
        echo "\texpired: = " . $key['expired_at'] . "\n";
    }
}

xml-rpc_apikeys.php

 new xmlrpcval($apikey),
                    'username' => new xmlrpcval('admin'),
                    'password' => new xmlrpcval('021rdb089'),
                    'expired' => new xmlrpcval(false)
                ),
                'struct');
$f = new xmlrpcmsg('apikeys', 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 "All API Keys for your account:\n";
    foreach ($retval as $key) {
        echo "key = " . $key['apikey'] . "\n";
        echo "\tcreated: = " . $key['created_at'] . "\n";
        echo "\texpired: = " . $key['expired_at'] . "\n";
    }
} else {
    echo "Unable to get API keys!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

mgapi_apikeys.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)
 
username = "username"
password = "password"
expired = False
 
retval = api.apikeys(username, password, expired)
if api.errorCode:
    print "Unable to get API keys!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "All API Keys for your account:"
    for key in retval:
        print "key = ", key['apikey']
        print "\tcreated: = ", key['created_at']
        print "\texpired: = ", key['date_expired']

apikeyAdd()

By using login data of Mailigen user, you can add a new API key that can be used afterwards in order to connect to Mailigen account.

apikeyAdd(string $username, string $password) : string
Input parameters
  • username password
Information obtained
  • new APIkey

Examples

mgapi_apikeyAdd.php

apikeyAdd($username, $password);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to add new API key!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Returned new API key: " . $retval . "\n";
}

xml-rpc_apikeyAdd.php

 new xmlrpcval($apikey),
                    'username' => new xmlrpcval('username'),
                    'password' => new xmlrpcval('password')
                ),
                'struct');
$f = new xmlrpcmsg('apikeyAdd', 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 "Returned new API key: " . $retval . "\n";
} else {
    echo "Unable to add new API key!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

mgapi_apikeyAdd.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)
 
username = "username"
password = "password"
 
retval = api.apikeyAdd(username, password)
if api.errorCode:
    print "Unable to add new API key!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Returned new API key: ", retval

apikeyExpire()

By using login data of Mailigen user, you can deactivate API key that will not be usable after deactivation request.

apikeyExpire(string $username, string $password) : boolean
Input parameters
  • username
  • password
Information obtained
  • true, if deactivation of API key has succeeded.

Examples

mgapi_apikeyExpire.php

apikeyExpire($username, $password);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to expire API key!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Returned: " . $retval . "\n";
}

xml-rpc_apikeyExpire.php

 new xmlrpcval($apikey),
                    'username' => new xmlrpcval('username'),
                    'password' => new xmlrpcval('password')
                ),
                'struct');
$f = new xmlrpcmsg('apikeyExpire', 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 "Returned: " . $retval . "\n";
} else {
    echo "Unable to expire API key!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

Examples

mgapi_apikeyExpire.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)
 
username = "username"
password = "password"
 
retval = api.apikeyExpire(username, password)
if api.errorCode:
    print "Unable to expire API key!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Returned: ", retval

login()

By using login data of Mailigen user, you can find an API key, but if there is no API key, it will be created.

login(string $username, string $password) : string
Input parameters
  • username
  • password
Information obtained
  • API key (if there is no API key, it will be created)

Examples

mgapi_login.php

login($username, $password);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to get API key!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Returned API key: " . $retval . "\n";
} 

xml-rpc_login.php

 new xmlrpcval('username'),
                    'password' => new xmlrpcval('password')
                ),
                'struct');
$f = new xmlrpcmsg('login', 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 "Returned API key: " . $retval . "\n";
} else {
    echo "Unable to get API key!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

mgapi_login.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)
 
username = "username"
password = "password"
 
retval = api.login(username, password)
if api.errorCode:
    print "Unable to get API key!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Returned API key: ", retval

ping()

Ping – this is a way to check if API key is active and if there is a response from Mailigen server. If problems are detected, server returns a notification.

ping() : string
Information obtained
  • Message “Everything is ok!” in case everything works. Otherwise, an error message is returned.

Examples

mgapi_ping.php

ping();
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to ping!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Returned: " . $retval . "\n";
}

xml-rpc_ping.php

 new xmlrpcval($apikey)
                ),
                'struct');
$f = new xmlrpcmsg('ping', 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 "Returned: " . $retval . "\n";
} else {
    echo "Unable to ping!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

mgapi_ping.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)
 
retval = api.ping()
if api.errorCode:
    print "Unable to ping!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Returned: ", retval

getAccountDetails()

Full information about Mailigen user account can be obtained by request: information about activities, contact information about Mailigen user, as well as information about bills.

getAccountDetails() : array
Information obtained

User account details is represented as an array that includes:

  • user_id - Mailigen user ID
  • username - user name
  • member_since - date of user creating a Mailigen user account
  • is_trial - whether Mailigen user is only a trial account user (true, false)
  • is_epicfree - whether Mailigen user is an Epic free account user (true, false)
  • plan_type - current price plan (plan, credit)
  • plan_high - email limit (how many contacts are in the monthly plan)
  • emails_left - number of emails that can be sent
  • first_payment - date of the first payment
  • last_payment - date of the last payment
  • times_logged_in - how many times user has logged in (via web)
  • last_login - date of the last login (via web)
  • contact - contact information. Array consisting of:
    • fname - first name
    • lname - last name
    • email - email
    • company - company name
    • address1 - address
    • city - city
    • state - state
    • zip - ZIP code
    • country - country
    • url - website address
    • phone - phone number
    • fax - fax number
  • email_senders - list of email senders. Each email sender is represented as an array that includes:
    • name - sender name
    • email - email
    • company - company name
    • address1 - address
    • city - city
    • state - state
    • zip - ZIP code
    • country - country
      The first email sender in the list is the account user. Then comes additional email senders if any are defined and verified.
  • sms_senders - list of SMS senders. Each SMS sender is represented as an array that includes:
    • name - sender name
    • phone - company name
    • company - company name
  • orders - information about bills. Array consisting of: 
    • invoice - bill number
    • plan_type - price plan (plan, credit)
    • plan_high - email limit (how many contacts are in the monthly plan). For plan_type credit this entry is not defined.
    • price - price
    • currency - currency
    • created_at - date of issue
    •  date_expired - date of plan expiration

Examples

mgapi_getAccountDetails.php

getAccountDetails();
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to get account info!\n";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Returned:\n";
    foreach ($retval as $key => $value) {
        if (!is_array($value)) {
            echo "\t" . $key . " = " . $value . "\n";
        } else {
            echo "\t" . $key . ":\n";
            foreach ($value as $k => $v) {
                if (!is_array($v)) {
                    echo "\t\t" . $k . " = " . $v . "\n";
                } else {
                    echo "\t\t" . ($k + 1) . ".\n";
                    foreach ($v as $k_ => $v_) {
                        echo "\t\t\t" . $k_ . " = " . $v_ . "\n";
                    }
                }
            }
        }
    }
}

xml-rpc_getAccountDetails.php

 new xmlrpcval($apikey)
                ),
                'struct');
$f = new xmlrpcmsg('getAccountDetails', 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 "Returned:\n";
    foreach ($retval as $key => $value) {
        if (!is_array($value)) {
            echo "\t" . $key . " = " . $value . "\n";
        } else {
            echo "\t" . $key . ":\n";
            foreach ($value as $k => $v) {
                if (!is_array($v)) {
                    echo "\t\t" . $k . " = " . $v . "\n";
                } else {
                    echo "\t\t" . ($k + 1) . ".\n";
                    foreach ($v as $k_ => $v_) {
                        echo "\t\t\t" . $k_ . " = " . $v_ . "\n";
                    }
                }
            }
        }
    }
} else {
    echo "Unable to get account info!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}

mgapi_getAccountDetails.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)
 
retval = api.getAccountDetails()
if api.errorCode:
    print "Unable to get account info!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    print "Returned"
    for key,value in retval.items():
        if isinstance(value, dict):
            print "\t", key
            for k,v in value.items():
                if isinstance(v, dict):
                    print "\t\t%d" % (k + 1)
                    for k_,v_ in v.items():
                        print "\t\t\t", k_, " = ", v_
                elif isinstance(v, list):
                    print "\t\t%d" % (k + 1)
                    for k_,v_ in enumerate(v):
                        print "\t\t\t", k_, " = ", v_
                else:
                    print "\t\t", k, " = ", v
        elif isinstance(value, list):
            print "\t", key
            for k,v in enumerate(value):
                if isinstance(v, dict):
                    print "\t\t%d" % (k + 1)
                    for k_,v_ in v.items():
                        print "\t\t\t", k_, " = ", v_
                elif isinstance(v, list):
                    print "\t\t%d" % (k + 1)
                    for k_,v_ in enumerate(v):
                        print "\t\t\t", k_, " = ", v_
                else:
                    print "\t\t", k, " = ", v
        else:
            print "\t", key, " = ", value

callServer()

Connection to the serveris performed and the required method that returns the result is called.

NoteThere is no need to call the function manually.
callServer(string $method, array $params)

httpBuildQuery()

The function httpBuildQuery() is defined for http_build_query systems where there is no such function.

httpBuildQuery(array $params, string $key)

© 2010-2017 Mailigen. All rights reserved.