Function is used to connect API. It is necessary to use API key as an additional parameter.
MGAPI(string $apikey)
User account details are represented as an array that includes:
require_once 'inc/MGAPI.class.php'; require_once 'inc/config.inc.php'; //contains apikey $api = new MGAPI($apikey);
from lib.config import * #contains apikey from lib.MGAPI import MGAPI api = MGAPI(apikey)
A 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
An array of API keys. Each key is represented as an array that includes:
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"; } }
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"; }
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']
By using login data of a user, you can add a new API key that can be used afterward in order to connect to the account.
apikeyAdd(string $username, string $password) : string
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"; }
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"; }
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
By using login data of a user, you can deactivate API key that will not be usable after deactivation request.
apikeyExpire(string $username, string $password) : boolean
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"; }
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"; }
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
By using login data of a user, you can find an API key, but if there is no API key, it will be created.
login(string $username, string $password) : string
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"; }
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"; }
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 – this is a way to check if API key is active and if there is a response from the server. If problems are detected, the server returns a notification.
ping() : string
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"; }
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"; }
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
Full information about user account can be obtained by request: information about activities, contact information about the user, as well as information about bills.
getAccountDetails() : array
User account details are represented as an array that includes:
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
Connection to the serveris performed and the required method that returns the result is called.
callServer(string $method, array $params)
The function httpBuildQuery() is defined for http_build_query systems where there is no such function.
httpBuildQuery(array $params, string $key)