Homepage | Client Area | Contact | Order Now »
WHMCS - The Complete Client Management, Billing & Support System
Article | Discussion | Edit | History Log in / create account

API:Example Usage

From WHMCS Documentation

Jump to: navigation, search

Communicating with the WHMCS API is very simple. The sample PHP code below is how we recommend interfacing with it.

<?php

$url = "http://www.yourdomain.com/whmcs/includes/api.php"; # URL to WHMCS API file
$username = "Admin"; # Admin username goes here
$password = "demo"; # Admin password goes here

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "addinvoicepayment";
$postfields["invoiceid"] = "1";
$postfields["transid"] = "TEST";
$postfields["gateway"] = "mailin";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

$data = explode(";",$data);
foreach ($data AS $temp) {
  $temp = explode("=",$temp);
  $results[$temp[0]] = $temp[1];
}

if ($results["result"]=="success") {
  # Result was OK!
} else {
  # An error occured
  echo "The following error occured: ".$results["message"];
}

?>


About the API System · Example API Usage · API Functions


Main Page
Getting Started
Using WHMCS & Howto's
Customising WHMCS
Modules
API
Contributions

Search
 

What links here
Recent Changes
Privacy Policy
General Disclaimer
Copyright © WHMCS Ltd. 2005-2008. All Rights Reserved. UK Registered Company #6265962. Vat No. GB 927 7746 76