Extending the WHMCS API and Fetching Invoice PDF’s

At work, we’re currently doing a FULL rebuild of our customer portal.  Part of the requirements of the system are that our staff must only be logging into one place.  At present they have to be logged into the portal AND WHMCS.  So in v2, we have to basically rebuild 90% of the WHMCS admin interface into our portal, and use the WHMCS API for manipulating data stored in WHMCS.  (We’re also adding a MongoDB caching layer for read access, and then using hooks in WHMCS to update the cache whenever data is modified).

We found a few ‘holes’ (read: missing functionality) in the WHMCS API, so had to see about adding an API to sit alongside WHMCS.  We did ask WHMCS how to go about writing custom API functions to use within the WHMCS API framework, but they came back saying this was not possible.  A fair bit of Googling around, and I managed to find a blog post detailing how to write custom API functions for WHMCS.  With a bit of work, we now have a nice basis for writing WHMCS API modules.  The first one I built for testing was for pulling Invoice PDF’s, which is not currently available in the WHMCS API.

And Voila, a simple WHMCS call such as:

Returned Variables

Then it’s a simple matter to go base64_decode($jsondata->pdf) (assuming you used json format and had done a json_decode() on the returned data…), and you have the binary data for the PDF, ready to save to disk, or pass back out to the user via HTTP.

 

9 Responses

You can follow any responses to this entry through the RSS 2.0 feed.

You can leave a response, or trackback from your own site.

  1. WHMCSLover says:

    AWESOME!!! THANK YOU!!!`

  2. Brano says:

    Hi, use your code but Im getting this error:

    Fatal error: Cannot redeclare getinvoicestatuscolour() in /xyxxxxxx/includes/invoicefunctions.php on line 6291459

    Can you help me please, how to solve it?

    • It may be that invoicefunctions is being included with the API functions automatically these days. Try changing the require line to look like this instead:

      if (!function_exists(‘getinvoicestatuscolour’)) {
      require(‘invoicefunctions.php’);
      }

  3. Douglas says:

    Hi Damien, I’m getting “No input file specified.”

    When I browse /includes/api.php this is returned, and also my curl_exec says the same.

    Any clues?

  4. Andrew says:

    for versions 7+ use _POSTbackup
    and use username and password instead of API secret and API key as they require access control now

    • Hey Andrew,

      Is it still working in WHMCS 7.4 using these changes? Finally looking at our WHMCS 7 upgrade at work in the next few weeks, have been dreading if we have to break our custom API calls (> 50 of them) out into another container, separate from WHMCS..

Leave a Reply