MBAPI Introduction

Making a remote call to your MBAPI requires passing XML input to your /lib-modernbill/include/lib-mbapi/remote.php page.

Your XML string should contain your admin access hash. This hash will allow access to all MBAPI commands. API access will be limited by IP address. Any number of IP addresses can be added to allow remote access from any number of servers.

Sample Select XML

<mbapi>
  <remoteAccessHash>4ad1bf8dfdb9aabd6a4efe8df07b3c12</remoteAccessHash>
  <command>GetClients</command>

  <subCommand></subCommand>
  <params>
    <clientFirstName>John2</clientFirstName>
  </params>
</mbapi>

Sample Update XML

<mbapi>

  <remoteAccessHash>4ad1bf8dfdb9aabd6a4efe8df07b3c12</remoteAccessHash>
  <command>SetClients</command>
  <subCommand>update</subCommand>  (update and insert are allowed.)
  <params>

    <clientID>5</clientID> (required for update)
    <clientFirstName>Jim</clientFirstName>
  </params>
</mbapi>

URL Encoded Get example

https://mydomainname.com/modernbill/lib-modernbill/include/lib-mbapi/remote.php?input=%3Cmbapi%3E%3CremoteAccessHash%3
E4ad1bf9dfdb8aabd6a4efe8df07b3c12%3C%2FremoteAccessHash%3E%3Ccommand%3EGetClients%3
C%2Fcommand%3E%3CsubCommand%3E%3C%2FsubCommand%3E%3C%2Fmbapi%3E

PHP cURL Post example

<?PHP
//Sample XML
$xml = "
<mbapi>

  <remoteAccessHash>4ad1bf8dfdb9aabd6a4efe8df07b3c12</remoteAccessHash>
  <command>GetClients</command>
  <subCommand></subCommand>
  <showXMLHeader>1</showXMLHeader>

  <params>
    <clientFirstName>John2</clientFirstName>
    <getContactData>1</getContactData>
    <getPackageData>1</getPackageData>

  </params>
</mbapi>";

// URL to your Modernbill
$url = "https://mydomainname.com/lib-modernbill/include/lib-mbapi/remote.php";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_VERBOSE,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "input=".$xml);

$data=curl_exec($ch);
$curlError = curl_error($ch);

if($curlError) {
	echo "Curl Error: ".$curlError."<br>";
} else {
	//Good call, show result
	header("Content-Type: text/xml");
	print_r($data);
}
?>