drosendo Posted April 2, 2015 Share Posted April 2, 2015 Create a file in whmcsfolder/includes/api/. Label it in the name of the API call getproductaddons.php, all lowercase. Paste in the code (feel free to contirbute): <?php if (!defined("WHMCS")) { die("This file cannot be accessed directly"); } function getParams($vars) { $param = array('action' => array(), 'params' => array()); if (isset($vars['cmd'])) { //Local API mode $param['action'] = $vars['cmd']; $param['params'] = (object) $vars['apivalues1']; $param['adminuser'] = $vars['adminuser']; } else { //Post CURL mode $param['action'] = $vars['_POST']['action']; unset($vars['_POST']['username']); unset($vars['_POST']['password']); unset($vars['_POST']['action']); $param['params'] = (object) $vars['_POST']; } return (object) $param; } try { // Get the arguments $vars = get_defined_vars(); $postFields = getParams($vars); // Block of code to update the whmcs details $pkg = addons($pid); // Block ends here $apiresults = array("result" => "success", "addons" => $pkg); } catch (Exception $e) { $apiresults = array("result" => "error", "message" => $e->getMessage()); } function addons($pid) { $pkg = array(); $pkgIndex = 0; $table = "tbladdons"; $fields = "*"; $where = array("showorder" => 'on'); $result = select_query($table, $fields, $where); while ($row = mysql_fetch_assoc($result)) { if ($row['packages'] != '') { $packages = explode(",", $row['packages']); foreach ($packages as $package) { if ($package == $pid) { $pkg[$pkgIndex]['id'] = $row['id']; $pkg[$pkgIndex]['name'] = $row['name']; $pkg[$pkgIndex]['description'] = $row['description']; if ($row['billingcycle'] == "Free Account") { $pkg[$pkgIndex]['cost'] = 0; } else { $pkg[$pkgIndex]['cost'] = prodPrice($row['id'], "monthly", 'addon'); // addon prices allways in 'monthly' field, independently of Billing Cycle. } $pkg[$pkgIndex]['cycle'] = $row['billingcycle']; $pkgIndex++; } } } } return $pkg; } function prodPrice($pid, $cycle = NULL, $type = 'product', $currency = '1') { $table = "tblpricing"; $fields = "monthly,quarterly,semiannually,annually,biennially"; $where = array("type" => $type, "currency" => $currency, "relid" => $pid); $limits = "1"; $result = select_query($table, $fields, $where, '', '', $limits); while ($addon = mysql_fetch_assoc($result)) { return $addon[$cycle]; } } Save file, and now you can use it: $command = "getproductaddons"; $adminuser = "admin"; $values["pid"] = 5; $results = localAPI($command,$values,$adminuser); All the best! Please give support! 0 Quote Link to comment Share on other sites More sharing options...
Alex - Arvixe Posted April 11, 2015 Share Posted April 11, 2015 Whilst I can see how this could be useful, why wouldn't it be possible to use: http://docs.whmcs.com/API:Get_Clients_Addons Filtering it down by adding a service ID? 0 Quote Link to comment Share on other sites More sharing options...
tgiwa Posted May 17, 2018 Share Posted May 17, 2018 On 4/11/2015 at 10:22 PM, Alex - Arvixe said: Whilst I can see how this could be useful, why wouldn't it be possible to use: http://docs.whmcs.com/API:Get_Clients_Addons Filtering it down by adding a service ID? I know this is an old post but this wont work because it will retrieve only the services added to the first client. If you want all available addons for a particular service, that doesnt seem available via the api 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.