Jump to content

API from any IP

Recommended Posts



I made a small piece of code that i think could help out others with a similar issue.

I have about hundred servers that is sending welcome emails out themself instead of having WHMCS to do it. That was annoying since i couldn't resend old emails, so i decided to use the WHMCS API to send emails. But i quickly ran into an issue - i had to add every single server IP on the API allow list. As i couldn't find an option to disable this allow list, i had to figure something else out. I ended up with writing a small PHP script that acts as a proxy to the API, so i only would have to whitelist the IP of the webserver. Simply copy/paste the following code into whmcs/includes/localapi.php (actually localapi.php can be called anything), and then use that file instead of api.php:



$ch = curl_init();

$url = str_replace('/'.basename(__FILE__),'/api.php',$_SERVER['REQUEST_URI']);

if (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on') {
   curl_setopt($ch, CURLOPT_URL, 'https://'.$_SERVER['HTTP_HOST'].$url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
} else {
   curl_setopt($ch, CURLOPT_URL, 'http://'.$_SERVER['HTTP_HOST'].$url);

if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

// Lighttpd doesn't support the Expect header.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));




Best regards,


Share this post

Link to post
Share on other sites

Not to bump an old post, but I've got this to work, however, I'm wanting to upgrade a product, and I am getting Service ID Not found, when the service exists in the system.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.


Important Information

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