Jump to content

PDF Invoices via API


wellconnit

Recommended Posts

Hi Guys,

 

A much asked for feature over the last few years for API users has been the ability to retrieve PDF Invoices from the system.

 

I stumbled across a link from The Wandering System Admin who has done a great job at dissecting the system and getting it to spit out a PDF invoice. (http://thewanderingsysadmin.net/?p=35)

However I'm having a bit of trouble getting it working.

Quote

<?PHP

if (!defined("WHMCS")) {
  die("This file cannot be accessed directly");
}

function buildParams($vars)
{
  $param = array(
    'action' => array(),
    'params' => array()
  );
  
  if (isset($vars['cmd'])) {
    $param['action']    = $vars['cmd'];
    $param['params']    = (object) $vars['apivalues1'];
    $param['adminuser'] = $vars['adminuser'];
  } else {
    $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 = buildParams($vars);
  
  // Include the WHMCS invoicefunctions
  if (!function_exists('pdfInvoice')) {
    require_once('invoicefunctions.php');
  }

  $pdfdata = pdfInvoice($postFields->params->invoiceid);
  
  $doc = base64_encode($pdfdata);
  
  $apiresults = array(
    "result" => "success",
    "pdf" => $doc,
    "message" => "Success Message"
  );
  
}
catch (Exception $e) {

  $apiresults = array(
    "result" => "error",
    "message" => $e->getMessage()
  );
}

I've created the request and passed it $username,$password & a static invoice ID of 10 however I'm getting a response of, 

Quote

array(2) { ["result"]=> string(5) "error" ["message"]=> string(59) "Invalid Permissions: API action "genpdffile" is not allowed" }

I've created the api request file in /includes/api/genpdffile.php however it's still not working.

 

Happy to drop the working code once I get it, because I know a few people are looking for it on here, and WHMCS support are yet to implement this natively.

 

Thanks to anyone with any ideas.

Anyone can follow the ticket if they want to keep updated on the issue.

Edited by wellconnit
Link to comment
Share on other sites

Upon further investigation I believe this error can be attributed to WHMCS stupidly disabling Custom API's in 7.4 without providing a real platform for external users to fix 'feature holes' within the system. Using Modules isn't really a convinient way to solve the issues that have been brought about by restricting the use of API calls.

If anyone has any insight on this I'd be happy to test it out.

 

Thanks.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated