Skip to main content

Can the WHMCS API retrieve Product Bundle information?

    Recent versions of WHMCS introduce a feature called "Product Bundles". The idea is simple - a single link combines a number of products, possibly with a specific set of Configurable Options. These combinations can then be assigned discounts unique to that Bundle.
    This comes in handy for a variety of different scenarios, for example in WHMCS instances where multiple brands are in play and you want to run a sale on a single brand that is still sold on other sites.     I recently encountered a situation that involved integrating a pre-existing pricing form within a CMS platform (think Joomla/Wordpress/Drupal/etc) with an order form and series of products with WHMCS. Not only did the signup buttons on the CMS page for each product need to connect to the corresponding WHMCS order form page, but pricing and product details on the CMS page needed to be generated dynamically from information stored in WHMCS, because updating two platforms to make simple price changes sucks and invites user error.
    The easiest way to do this would be to setup an individual product within WHMCS for each product on the CMS page, use the product link generated for the product upon creation in WHMCS and the `Get_Products` WHMCS API call to generate the product details.
    Ultimately this approach proved problematic in my case. Each product on the CMS represented a preset of Configurable Options, but customers needed to be able to easily upgrade these options either during a purchase or after the purchase. I also wanted to be able to easily pipe these configurable options as input to third party modules and custom scripts that would be used to automatically deploy the products based on customer selections (think automatically handling routing based on how many IP addresses a customer buys). Plus, all of these options were part of the primary product and wouldn't make sense to bill them independently like WHMCS' Add-On products.
    I quickly encountered a problem. The `Get_Products` WHMCS API call only allows developers to filter results by Product ID number ("pid") and Product Group ID number ("gid"). This was unacceptable - in order for me to return results by Product Bundle, I needed to search by Bundle ID ("bid"). It became apparent that there was no simple existing method within WHMCS to accomplish this. So, I wrote my own.
    Googling around I noticed I am not the only person who has needed to accomplish something similar, so I am posting the results here in the hope that it can help save someone else a few minutes of irritation or even having people needlessly create a bunch of different products.
    The example I have posted here produces results in json, but it can be pretty easily modified to generate xml instead. Its been tested thoroughly in WHMCS v6.3. The data can be imported into Wordpress using this guide or into Drupal using this guide (requires Views 3 or above & Views JSON Query).