Skip to content
Last updated

UpgradeProduct

Upgrade, or calculate an upgrade on, a product

Request Parameters

ParameterTypeDescriptionRequired
actionstring"UpgradeProduct"Required
serviceidintThe ID of the service to updateRequired
calconlyboolOnly calculate the upgrade amountOptional
paymentmethodstringThe upgrade payment method in system format (e.g. paypal)Required
typestringThe type of upgrade ('product', 'configoptions')Required
newproductidintThe ID of the new productOptional
newproductbillingcyclestringThe new products billing cycleOptional
promocodestringThe promotion code to apply to the upgradeOptional
configoptionsarrayIf type=configoptions - Config options to include in the upgrade. Keys represent config option IDs while their values represent the config option choice ID or value (depending on type). In the example provided, config option ID=1 is a dropdown specifying option ID 4, and config option ID=2 is a quantity specifying a desire for 5 units.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
upgradeinprogressboolIs an upgrade in progress (for calconly)

Example Request (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'UpgradeProduct',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'serviceid' => '1',
            'paymentmethod' => 'paypal',
            'newproductbillingcycle' => 'monthly',
            'type' => 'product',
            'newproductid' => '11',
            'configoptions' => [1 => 4, 2 => 5],
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'UpgradeProduct';
$postData = array(
    'serviceid' => '1',
    'paymentmethod' => 'paypal',
    'newproductbillingcycle' => 'monthly',
    'type' => 'product',
    'newproductid' => '11',
    'configoptions' => [1 => 4, 2 => 5],
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

Example Response JSON

{
    "result": "success",
    "oldproductid": "12",
    "oldproductname": "5 Years",
    "newproductid": 11,
    "newproductname": "4 Years",
    "daysuntilrenewal": 13,
    "totaldays": 30,
    "newproductbillingcycle": "monthly",
    "price": "$-8.67 USD",
    "id": "44",
    "orderid": 73,
    "order_number": "9093331404",
    "invoiceid": null
}

Error Responses

Possible error condition responses include:

  • Service ID Not Found
  • Unable to accept upgrade order. Previous upgrade invoice for service is still unpaid.
  • Invalid Payment Method. Valid options include xxx
  • Invalid Upgrade Type

Version History

VersionChangelog
1.0Initial Version