Skip to content
Last updated

AddProduct

Adds a product to the system to be available for purchase

Request Parameters

ParameterTypeDescriptionRequired
actionstring"AddProduct"Required
namestringThe name of the product to be addedRequired
gidintThe id of the product group to add the productRequired
slugstringThe friendly name of the product. Will be generated if not supplied.Optional
typestringOne of 'hostingaccount', 'reselleraccount', 'server' or 'other'Optional
stockcontrolboolSet to true to enable stock control on the productOptional
qtyintHow much of this product is in stockOptional
paytypestringThe payment type of the product. One of 'free', 'onetime', 'recurring'Optional
hiddenboolShould the product be hidden from the client order formOptional
showdomainoptionsboolShould the product show the domain registration options.Optional
taxboolDoes tax apply to the product.Optional
isFeaturedboolShould the product be featured in the Product Group.Optional
proratabillingboolIs pro-rata billing enabled for this product.Optional
descriptionstringThe description of the product to show on the product listing in the cartOptional
shortdescriptionstringThe short description of the product to show in specific areas of the cart.Optional
taglinestringThe tagline of the product to show in specific areas of the cart.Optional
colorstringThe color to associate with the product in specific areas of the cart.Optional
welcomeemailintThe id of the Email Template to use as the welcome email. Product/Service Messages onlyOptional
proratadateintSee https://go.whmcs.com/1981/products#pricingOptional
proratachargenextmonthintSee https://go.whmcs.com/1981/products#pricingOptional
subdomainstringA comma separated list of subdomains to offer on the domain register page. eg: .domain1.com,.domain2.comOptional
autosetupstringWhen should the product be automatically setup. One of '' (never), 'on' (pending order), 'payment' (on payment), 'order' (on order)Optional
modulestringThe server module system name to associate with the product. eg: cpanel, autorelease, pleskOptional
servergroupidintThe server group id used on product creation to associate an appropriate serverOptional
configoption1mixedThe first module configuration valueOptional
configoption2mixedThe second module configuration valueOptional
configoption3mixedThe third module configuration valueOptional
configoption4mixedThe fourth module configuration valueOptional
configoption5mixedThe fifth module configuration valueOptional
configoption6mixedThe sixth module configuration valueOptional
orderintThe order to in which to display on the order formOptional
pricingarrayThe pricing array to associate with the product. Format: $pricing[currencyid][cycle]. See Example.Optional
recommendationsarrayThe recommendations array to associate with the product in the following format: ['id' => productid, 'order' => integer] (See example.)Optional
ondemandrenewalconfigurationoverrideboolWhether the product uses custom on-demand renewal settings.Optional
ondemandrenewalsenabledboolWhether on-demand renewals are enabled for the product. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodmonthlyintThe period (in days) during which clients can place early renewal orders for the monthly billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodquarterlyintThe period (in days) during which clients can place early renewal orders for the quarterly billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodsemiannuallyintThe period (in days) during which clients can place early renewal orders for the semi-annually billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodannuallyintThe period (in days) during which clients can place early renewal orders for the annually billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodbienniallyintThe period (in days) during which clients can place early renewal orders for the biennially billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional
ondemandrenewalperiodtrienniallyintThe period (in days) during which clients can place early renewal orders for the triennially billing cycle. Requires $ondemandrenewalconfigurationoverride be set to true.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
pidintThe id of the newly created product

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' => 'AddProduct',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'type' => 'other',
            'gid' => '1',
            'name' => 'Sample Product',
            'welcomeemail' => '5',
            'paytype' => 'recurring',
            'pricing' => array(1 => array('monthly' => 1.00, 'msetupfee' => 1.99, 'quarterly' => 2.00, 'qsetupfee' => 1.99, 'semiannually' => 3.00, 'ssetupfee' => 1.99, 'annually' => 4.00, 'asetupfee' => 1.99, 'biennially' => 5.00, 'bsetupfee' => 1.99, 'triennially' => 6.00, 'tsetupfee' => 1.99)),
            'recommendations' => array(array('id' => 1, 'order' => 0), array('id' => 2, 'order' => 1)),
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'AddProduct';
$postData = array(
    'type' => 'other',
    'gid' => '1',
    'name' => 'Sample Product',
    'welcomeemail' => '5',
    'paytype' => 'recurring',
    'pricing' => array(1 => array('monthly' => 1.00, 'msetupfee' => 1.99, 'quarterly' => 2.00, 'qsetupfee' => 1.99, 'semiannually' => 3.00, 'ssetupfee' => 1.99, 'annually' => 4.00, 'asetupfee' => 1.99, 'biennially' => 5.00, 'bsetupfee' => 1.99, 'triennially' => 6.00, 'tsetupfee' => 1.99)),
    'recommendations' => array(array('id' => 1, 'order' => 0), array('id' => 2, 'order' => 1)),
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

Example Response JSON

{
    "result": "success"
}

Error Responses

Possible error condition responses include:

  • You must supply a name for the product
  • You must supply a valid Product Group ID
  • You must supply a valid welcome email ID
  • Invalid product type. Must be one of "hostingaccount", "reselleraccount", "server" or "other"
  • Invalid pay type. Must be one of "free", "onetime" or "recurring"
  • Invalid autosetup value. Must be one of "", "on", "order" or "payment"
  • The color must be a valid hexadecimal value.
  • The recommendation product ID is invalid. This must be an existing product ID.

Version History

VersionChangelog
1.0Initial Version
8.3Added slug parameter