How can we improve WHMCS?

Share, discuss and vote for what you would like to see added to WHMCS

AddProduct api should have unique restraint

  • jimlongo shared this idea 3 years ago
  • Developers
  • 2 Comments


The LocalAPI call to 'AddProduct' will duplicate a product if it already exists. This seems problematic. Have to always check if the product already exists.

There should be a unique constraint on "name", so no duplicate products exist.

2 Comments

Login to post a comment.

This is a problem when creating products.

I have a module function that populates a catalog based on SKU entries in our API.
So I get the info and create some products.


$command = 'AddProduct';
$postdata = Array
(
[name] => Latitude Premium
[gid] => 3
[type] => other
[paytype] => recurring
[description] => Latitude Premium
[autosetup] => order
[module] => TCS
[configoption1] => yola_prem
[order] => 1
[pricing] => Array
(
[1] => Array
(
[monthly] => 14.99
)
)

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


If that button gets clicked again it will create the exact same product again.
That's not good.

So, check for the one unique thing about that product [configoption1], unfortunately this does not get returned by $command = 'GetProducts';

The suggestion that name should be unique is not really the critical part, it's that something about a product should be unique.

At a minimum at least that $command = 'GetProducts'; should return [configoption1] through [configoption24] so these can be checked against before duplicating the product.
Hi Jim,
Thanks for your suggestion.
The Product Name is not a unique field in general. It is possible to create products with the same name in the UI, and there are a number of use-cases where this it is important to have duplicate product names.
Can you elaborate on the particular use-case you have for enforcing unique product names via the API only?