# API: Apply coupon
# applyInvoiceCoupon
Apply coupon to invoice.
# Required parameters
Parameter | Description |
---|---|
id | Invoice ID |
applycoupon | Coupon |
# Request
GET /admin/api.php?api_id=API_ID&api_key=API_KEY&call=applyInvoiceCoupon&id=ID&applycoupon=APPLYCOUPON
# PHP Samples
$url = 'http://url_to_hb.com/admin/api.php';
$post = [
'call' => 'applyInvoiceCoupon',
'api_id' => $API_ID,
'api_key' => $API_KEY,
'id' => $ID,
'applycoupon' => $APPLYCOUPON,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
$return = json_decode($data, true);
print_r($return);
include 'class.hbwrapper.php';
HBWrapper::setAPI('http://url_to_hb.com/admin/api.php','API ID','API Key');
$params = [
'id' => $ID,
'applycoupon' => $APPLYCOUPON,
];
$return = HBWrapper::singleton()->applyInvoiceCoupon($params);
print_r($return);
/* Use this method to access HostBill api from HostBill modules */
$api = new ApiWrapper();
$params = [
'id' => $ID,
'applycoupon' => $APPLYCOUPON,
];
$return = $api->applyInvoiceCoupon($params);
print_r($return);
# Response
{
"success": true,
"call": "applyInvoiceCoupon",
"server_time": 1460987523,
"info": [
"The coupon has been added to the invoice"
]
}